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.



321
322
323
# File 'lib/riveter/attributes.rb', line 321

def options
  @options
end

Instance Method Details

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



343
344
345
346
347
348
# File 'lib/riveter/attributes.rb', line 343

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



358
359
360
361
362
363
364
365
366
# File 'lib/riveter/attributes.rb', line 358

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

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



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/riveter/attributes.rb', line 323

def initialize(params=nil, options={})
  # assign default values
  self.class._attributes.each do |name, attribute_info|
    next unless attribute_info.default?
    value = attribute_info.default
    send("#{name}=", value.respond_to?(:call) ? value.call : value)
  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)


353
354
355
# File 'lib/riveter/attributes.rb', line 353

def persisted?
  false
end