Created
June 15, 2024 16:19
-
-
Save AndyObtiva/294623c5506cfa0afe6534ad2c56916c to your computer and use it in GitHub Desktop.
Glimmer DSL for Web - Regular Sample - Todo MVC - Models - Todo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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