mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-26 02:36:11 +01:00
move model validation into pattern classes and link from recurring_todo model
This commit is contained in:
parent
776a046465
commit
29b815e998
7 changed files with 201 additions and 77 deletions
|
|
@ -6,6 +6,27 @@ module RecurringTodos
|
|||
super user
|
||||
end
|
||||
|
||||
def every_x_week
|
||||
get :every_other1
|
||||
end
|
||||
|
||||
{ monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6, sunday: 0 }.each do |day, number|
|
||||
define_method("on_#{day}") do
|
||||
on_xday number
|
||||
end
|
||||
end
|
||||
|
||||
def on_xday(n)
|
||||
get(:every_day) && get(:every_day)[n, 1] != ' '
|
||||
end
|
||||
|
||||
def validate
|
||||
super
|
||||
errors[:base] << "Every other nth week may not be empty for weekly recurrence setting" if every_x_week.blank?
|
||||
something_set = %w{sunday monday tuesday wednesday thursday friday saturday}.inject(false) { |set, day| set || self.send("on_#{day}") }
|
||||
errors[:base] << "You must specify at least one day on which the todo recurs" unless something_set
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue