Class: LiquidPlanner::LiquidPlannerResource
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- LiquidPlanner::LiquidPlannerResource
- Defined in:
- lib/liquidplanner/liquidplanner_resource.rb
Overview
generic resource, extended by all LiquidPlanner::Resources
Direct Known Subclasses
Resources::Account, Resources::Luggage, Resources::Workspace, Resources::WorkspaceResource
Instance Method Summary collapse
- #get_raw(custom_method_name, options = {}) ⇒ Object
-
#load(attributes, remove_root = false, persisted = false) ⇒ Object
LiquidPlanner does not send back data that is already in the path (prefix_options), so merge any values that the object already had back into the prefix_options.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (private)
Special handling for creating associated resources. For instance:
workspace.create_task(:name=>'new task').create_estimate(:low_effort=>1, :high_effort=>3)
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/liquidplanner/liquidplanner_resource.rb', line 46 def method_missing(name, *args) if name.to_s =~ /^(create|build)_(.+)/ operation = $1.to_sym resource = $2 attributes = args.shift || {} klass = LiquidPlanner::Resources.const_get(resource.classify) obj = build_new_resource(klass, attributes) obj.save if operation == :create obj else super end end |
Instance Method Details
#get_raw(custom_method_name, options = {}) ⇒ Object
17 18 19 |
# File 'lib/liquidplanner/liquidplanner_resource.rb', line 17 def get_raw(custom_method_name, = {}) connection.get_raw(custom_method_element_url(custom_method_name, ), self.class.headers) end |
#load(attributes, remove_root = false, persisted = false) ⇒ Object
LiquidPlanner does not send back data that is already in the path (prefix_options), so merge any values that the object already had back into the prefix_options.
10 11 12 13 14 15 |
# File 'lib/liquidplanner/liquidplanner_resource.rb', line 10 def load(attributes, remove_root = false, persisted = false) = @prefix_options.clone super @prefix_options.merge!(){|k, old_attr,new_attr| old_attr || new_attr } self end |