mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-03 03:20:15 +01:00
Start major refactoring of recurring_todos. Started with creating new recurring todos.
All current and new tests pass
This commit is contained in:
parent
8e13059df1
commit
78c07d52b7
26 changed files with 1218 additions and 32 deletions
42
app/models/recurring_todos/abstract_repeat_pattern.rb
Normal file
42
app/models/recurring_todos/abstract_repeat_pattern.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module RecurringTodos
|
||||
|
||||
class AbstractRepeatPattern
|
||||
|
||||
def initialize(user, attributes)
|
||||
@attributes = attributes
|
||||
@user = user
|
||||
end
|
||||
|
||||
def build_recurring_todo
|
||||
@recurring_todo = @user.recurring_todos.build(mapped_attributes)
|
||||
end
|
||||
|
||||
def mapped_attributes
|
||||
@attributes
|
||||
end
|
||||
|
||||
def attributes
|
||||
mapped_attributes
|
||||
end
|
||||
|
||||
def map(mapping, key, source_key)
|
||||
mapping[key] = mapping[source_key]
|
||||
mapping.except(source_key)
|
||||
end
|
||||
|
||||
def get_selector(key)
|
||||
raise Exception.new, "recurrence selector pattern (#{key}) not given" unless @attributes.key?(key)
|
||||
raise Exception.new, "unknown recurrence selector pattern: '#{@attributes[key]}'" unless valid_selector?(@attributes[key])
|
||||
|
||||
selector = @attributes[key]
|
||||
@attributes = @attributes.except(key)
|
||||
return selector
|
||||
end
|
||||
|
||||
def valid_selector?(selector)
|
||||
raise Exception.new, "valid_selector? should be overridden in subclass of AbstractRepeatPattern"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue