Module: Her::Model::Attributes::ClassMethods

Defined in:
lib/her/model/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributes(*attributes) ⇒ Object

Define the attributes that will be used to track dirty attributes and validations

Examples:

class User
  include Her::Model
  attributes :name, :email
end

Parameters:

  • attributes (Array)


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/her/model/attributes.rb', line 187

def attributes(*attributes)
  define_attribute_methods attributes

  attributes.each do |attribute|
    attribute = attribute.to_sym

    unless instance_methods.include?(:"#{attribute}=")
      define_method("#{attribute}=") do |value|
        @attributes[:"#{attribute}"] = nil unless @attributes.include?(:"#{attribute}")
        self.send(:"#{attribute}_will_change!") if @attributes[:'#{attribute}'] != value
        @attributes[:"#{attribute}"] = value
      end
    end

    unless instance_methods.include?(:"#{attribute}?")
      define_method("#{attribute}?") do
        @attributes.include?(:"#{attribute}") && @attributes[:"#{attribute}"].present?
      end
    end
  end
end

#store_metadata(value = nil) ⇒ Object

Define the accessor in which the API response metadata (obtained from the parsing middleware) will be stored

Examples:

class User
  include Her::Model
   :server_data
end

Parameters:

  • store_metadata (Symbol)


231
232
233
# File 'lib/her/model/attributes.rb', line 231

def (value = nil)
  store_her_data(:metadata, value)
end

#store_response_errors(value = nil) ⇒ Object

Define the accessor in which the API response errors (obtained from the parsing middleware) will be stored

Examples:

class User
  include Her::Model
  store_response_errors :server_errors
end

Parameters:

  • store_response_errors (Symbol)


218
219
220
# File 'lib/her/model/attributes.rb', line 218

def store_response_errors(value = nil)
  store_her_data(:response_errors, value)
end