Class: RecurringTodos::RecurringTodosBuilder
- Inherits:
-
Object
- Object
- RecurringTodos::RecurringTodosBuilder
- Defined in:
- app/models/recurring_todos/recurring_todos_builder.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#tag_list ⇒ Object
readonly
Returns the value of attribute tag_list.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #attributes ⇒ Object
- #build ⇒ Object
- #create_builder(selector) ⇒ Object
- #errors ⇒ Object
-
#initialize(user, attributes) ⇒ RecurringTodosBuilder
constructor
A new instance of RecurringTodosBuilder.
- #parse_context ⇒ Object private
- #parse_dates ⇒ Object private
- #parse_project ⇒ Object private
- #pattern ⇒ Object
- #recurring_todo ⇒ Object
- #save ⇒ Object
- #saved_recurring_todo ⇒ Object
- #update(recurring_todo) ⇒ Object
- #valid_selector?(selector) ⇒ Boolean private
Constructor Details
#initialize(user, attributes) ⇒ RecurringTodosBuilder
Returns a new instance of RecurringTodosBuilder.
5 6 7 8 9 10 11 12 13 14 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 5 def initialize(user, attributes) @user = user @attributes = Tracks::AttributeHandler.new(@user, attributes) parse_dates parse_project parse_context @builder = create_builder(@attributes[:recurring_period]) end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
3 4 5 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 3 def builder @builder end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 3 def context @context end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
3 4 5 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 3 def project @project end |
#tag_list ⇒ Object (readonly)
Returns the value of attribute tag_list.
3 4 5 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 3 def tag_list @tag_list end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 3 def user @user end |
Instance Method Details
#attributes ⇒ Object
44 45 46 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 44 def attributes @builder.attributes end |
#build ⇒ Object
21 22 23 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 21 def build @builder.build end |
#create_builder(selector) ⇒ Object
16 17 18 19 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 16 def create_builder(selector) raise "Unknown recurrence selector in :recurring_period (#{selector})" unless valid_selector? selector eval("RecurringTodos::#{selector.capitalize}RecurringTodosBuilder.new(@user, @attributes)", binding, __FILE__, __LINE__) end |
#errors ⇒ Object
52 53 54 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 52 def errors @builder.errors end |
#parse_context ⇒ Object (private)
70 71 72 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 70 def parse_context @context, @new_context_created = @attributes.parse_collection(:context, @user.contexts) end |
#parse_dates ⇒ Object (private)
62 63 64 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 62 def parse_dates %w{end_date start_from}.each { |date| @attributes.parse_date date } end |
#parse_project ⇒ Object (private)
66 67 68 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 66 def parse_project @project, @new_project_created = @attributes.parse_collection(:project, @user.projects) end |
#pattern ⇒ Object
48 49 50 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 48 def pattern @builder.pattern end |
#recurring_todo ⇒ Object
40 41 42 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 40 def recurring_todo @builder.recurring_todo end |
#save ⇒ Object
29 30 31 32 33 34 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 29 def save @builder.save_project if @new_project_created @builder.save_context if @new_context_created return @builder.save end |
#saved_recurring_todo ⇒ Object
36 37 38 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 36 def saved_recurring_todo @builder.saved_recurring_todo end |
#update(recurring_todo) ⇒ Object
25 26 27 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 25 def update(recurring_todo) @builder.update(recurring_todo) end |
#valid_selector?(selector) ⇒ Boolean (private)
58 59 60 |
# File 'app/models/recurring_todos/recurring_todos_builder.rb', line 58 def valid_selector?(selector) %w{daily weekly monthly yearly}.include?(selector) end |