Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndyObtiva/294623c5506cfa0afe6534ad2c56916c to your computer and use it in GitHub Desktop.
Save AndyObtiva/294623c5506cfa0afe6534ad2c56916c to your computer and use it in GitHub Desktop.
Glimmer DSL for Web - Regular Sample - Todo MVC - Models - Todo
# Source: https://github.com/AndyObtiva/glimmer-dsl-web/blob/master/lib/glimmer-dsl-web/samples/regular/todo_mvc/models/todo.rb
Todo = Struct.new(:task, :completed, :editing, keyword_init: true) do
class << self
attr_writer :all
def all
@all ||= []
end
def active
all.select(&:active?)
end
def completed
all.select(&:completed?)
end
end
FILTERS = [:all, :active, :completed]
alias completed? completed
alias editing? editing
def active
!completed
end
alias active? active
def start_editing
return if editing?
@original_task = task
self.editing = true
end
def cancel_editing
return unless editing?
self.task = @original_task
self.editing = false
end
def save_editing
return unless editing?
self.editing = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment