Module: Oare::Resource::InstanceMethods
- Defined in:
- lib/active_resource_override/base.rb
Instance Attribute Summary collapse
-
#nested_attributes_values ⇒ Object
Returns the value of attribute nested_attributes_values.
Instance Method Summary collapse
- #create_path(options = {}, query_options = {}) ⇒ Object
- #encode(options = {}) ⇒ Object
- #errors ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #update_path(options = {}, query_options = {}) ⇒ Object
Instance Attribute Details
#nested_attributes_values ⇒ Object
Returns the value of attribute nested_attributes_values.
75 76 77 |
# File 'lib/active_resource_override/base.rb', line 75 def nested_attributes_values @nested_attributes_values end |
Instance Method Details
#create_path(options = {}, query_options = {}) ⇒ Object
93 94 95 |
# File 'lib/active_resource_override/base.rb', line 93 def create_path( = {}, = {}) self.class.create_path(.merge(), ) end |
#encode(options = {}) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/active_resource_override/base.rb', line 101 def encode(={}) if new? keys = nested_attributes_values.keys super(.merge(:methods => keys)) else super end end |
#errors ⇒ Object
110 111 112 |
# File 'lib/active_resource_override/base.rb', line 110 def errors @errors ||= Oare::Errors.new(self) end |
#initialize(attributes = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/active_resource_override/base.rb', line 77 def initialize(attributes = {}) @nested_attributes_values ||= {} self.class.instance_variable_get(:@nested_attributes).each do |key, value| @nested_attributes_values[key] = collection = attributes.delete(key) next unless collection collection.each do |index, associate_attributes| nested_model = value.to_s collection = [] collection[index.to_i] = nested_model.singularize.camelize.constantize.new(associate_attributes) instance_variable_set("@#{nested_model}", collection) end end super end |
#update_path(options = {}, query_options = {}) ⇒ Object
97 98 99 |
# File 'lib/active_resource_override/base.rb', line 97 def update_path( = {}, = {}) self.class.update_path(to_param, .merge(), ) end |