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


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

def attributes(*attributes)
  define_attribute_methods attributes

  attributes.each do |attribute|
    unless method_defined?(:"#{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 method_defined?(:"#{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


228
229
230
# File 'lib/her/model/attributes.rb', line 228

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


215
216
217
# File 'lib/her/model/attributes.rb', line 215

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