Module: Riveter::Attributes
Defined Under Namespace
Modules: ClassMethods, Converters Classes: AttributeInfo, Base
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #attributes(options = {}) ⇒ Object (also: #to_params)
-
#column_for_attribute(column) ⇒ Object
forms use this for getting column meta data.
- #initialize(params = nil, options = {}) ⇒ Object
-
#persisted? ⇒ Boolean
forms use this to determine the HTTP verb.
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
321 322 323 |
# File 'lib/riveter/attributes.rb', line 321 def @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(={}) 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, ={}) # 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 = .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
353 354 355 |
# File 'lib/riveter/attributes.rb', line 353 def persisted? false end |