Module: Oare::Resource::InstanceMethods

Defined in:
lib/active_resource_override/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nested_attributes_valuesObject

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(options = {}, query_options = {})
  self.class.create_path(prefix_options.merge(options), query_options)
end

#encode(options = {}) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/active_resource_override/base.rb', line 101

def encode(options={})
  if new?
    keys = nested_attributes_values.keys
    super(options.merge(:methods => keys))
  else
    super
  end
end

#errorsObject



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(options = {}, query_options = {})
  self.class.update_path(to_param, prefix_options.merge(options), query_options)
end