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

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) attributes(*attributes)

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)


182
183
184
185
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 182

def attributes(*attributes)
  define_attribute_methods attributes

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

    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      unless instance_methods.include?(:'#{attribute}=')
        def #{attribute}=(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}?')
        def #{attribute}?
          @attributes.include?(:'#{attribute}') && @attributes[:'#{attribute}'].present?
        end
      end
    RUBY
  end
end

- (Object) store_metadata(value = nil)

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)


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

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

- (Object) store_response_errors(value = nil)

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)


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

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