Module: Riveter::Attributes

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/riveter/attributes.rb

Defined Under Namespace

Modules: ClassMethods, Converters Classes: AttributeInfo, Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



328
329
330
# File 'lib/riveter/attributes.rb', line 328

def options
  @options
end

Instance Method Details

#attributes(options = {}) ⇒ Object Also known as: to_params



349
350
351
352
353
354
# File 'lib/riveter/attributes.rb', line 349

def attributes(options={})
  self.class._attributes.inject({}) do |list, (key, attribute_info)|
    list[key] = self.send(attribute_info.name)
    list
  end
end

#column_for_attribute(column) ⇒ Object

forms use this for getting column meta data



368
369
370
371
372
373
374
375
376
# File 'lib/riveter/attributes.rb', line 368

def column_for_attribute(column)
  attribute_info = self.class._attributes[column]
  OpenStruct.new(
    :name => attribute_info.name,
    :type => attribute_info.type,
    :null => !attribute_info.required?,
    :default => attribute_info.default
  )
end

#has_attribute?(column) ⇒ Boolean

Returns:

  • (Boolean)


363
364
365
# File 'lib/riveter/attributes.rb', line 363

def has_attribute?(column)
  self.class._attributes.key?(column)
end

#initialize(params = nil, options = {}) ⇒ Object



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/riveter/attributes.rb', line 330

def initialize(params=nil, options={})
  # assign default values
  self.class._attributes.each do |name, attribute_info|
    next unless attribute_info.default?
    send("#{name}=", attribute_info.evaluate_default(self))
  end

  @options = options.freeze

  # filter and clean params before applying
  apply_params(
    clean_params(
      filter_params(
        sanitize_for_mass_assignment(params)
      )
    )
  ) unless params.nil?
end

#persisted?Boolean

forms use this to determine the HTTP verb

Returns:

  • (Boolean)


359
360
361
# File 'lib/riveter/attributes.rb', line 359

def persisted?
  false
end