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.



78
79
80
# File 'lib/active_resource_override/base.rb', line 78

def nested_attributes_values
  @nested_attributes_values
end

Instance Method Details

#create_path(options = {}, query_options = {}) ⇒ Object



100
101
102
# File 'lib/active_resource_override/base.rb', line 100

def create_path(options = {}, query_options = {})
  self.class.create_path(prefix_options.merge(options), query_options)
end

#encode(options = {}) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/active_resource_override/base.rb', line 108

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

#errorsObject



117
118
119
# File 'lib/active_resource_override/base.rb', line 117

def errors
  @errors ||= Oare::Errors.new(self)
end

#initialize(attributes = {}, persisted = false) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/active_resource_override/base.rb', line 80

def initialize(attributes = {}, persisted = false)
  @attributes     = {}.with_indifferent_access
  @prefix_options = {}
  @persisted      = persisted

  @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



104
105
106
# File 'lib/active_resource_override/base.rb', line 104

def update_path(options = {}, query_options = {})
  self.class.update_path(to_param, prefix_options.merge(options), query_options)
end