Class: LiquidPlanner::LiquidPlannerResource

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/liquidplanner/liquidplanner_resource.rb

Overview

generic resource, extended by all LiquidPlanner::Resources

Instance Method Summary collapse

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, options = {})
  connection.get_raw(custom_method_element_url(custom_method_name, options), 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)
  initial_prefix_options = @prefix_options.clone
  super
  @prefix_options.merge!(initial_prefix_options){|k, old_attr,new_attr| old_attr || new_attr }
  self
end