Class: RecurringTodos::FormHelper
- Inherits:
-
Object
- Object
- RecurringTodos::FormHelper
show all
- Defined in:
- app/controllers/recurring_todos/form_helper.rb
Instance Method Summary
collapse
Constructor Details
#initialize(recurring_todo) ⇒ FormHelper
Returns a new instance of FormHelper.
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'app/controllers/recurring_todos/form_helper.rb', line 3
def initialize(recurring_todo)
@recurring_todo = recurring_todo
@method_map = {
"daily" => { prefix: "", method: daily_pattern },
"weekly" => { prefix: "", method: weekly_pattern },
"monthly" => { prefix: "", method: monthly_pattern },
"yearly" => { prefix: "", method: yearly_pattern },
"on" => { prefix: "on_", method: weekly_pattern }
}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/recurring_todos/form_helper.rb', line 39
def method_missing(method, *args)
if method.to_s =~ /^([^_]+)_(.+)$/
return @method_map[$1][:method].send(@method_map[$1][:prefix] + $2, *args) unless @method_map[$1].nil?
end
@recurring_todo.send(method, *args)
end
|
Instance Method Details
#create_pattern(pattern_class) ⇒ Object
17
18
19
20
21
|
# File 'app/controllers/recurring_todos/form_helper.rb', line 17
def create_pattern(pattern_class)
pattern = pattern_class.new(@recurring_todo.user)
pattern.build_from_recurring_todo(@recurring_todo)
pattern
end
|
#daily_pattern ⇒ Object
23
24
25
|
# File 'app/controllers/recurring_todos/form_helper.rb', line 23
def daily_pattern
@daily_pattern ||= create_pattern(DailyRecurrencePattern)
end
|
#monthly_pattern ⇒ Object
31
32
33
|
# File 'app/controllers/recurring_todos/form_helper.rb', line 31
def monthly_pattern
@monthly_pattern ||= create_pattern(MonthlyRecurrencePattern)
end
|
#weekly_pattern ⇒ Object
27
28
29
|
# File 'app/controllers/recurring_todos/form_helper.rb', line 27
def weekly_pattern
@weekly_pattern ||= create_pattern(WeeklyRecurrencePattern)
end
|
#yearly_pattern ⇒ Object
35
36
37
|
# File 'app/controllers/recurring_todos/form_helper.rb', line 35
def yearly_pattern
@yearly_pattern ||= create_pattern(YearlyRecurrencePattern)
end
|