module OnForm::Attributes
Public Instance Methods
[](attribute_name)
click to toggle source
the individual attribute methods are introduced by the expose_attribute class method. here we introduce some methods used for the attribute set as a whole.
# File lib/on_form/attributes.rb, line 6 def [](attribute_name) send(attribute_name) end
[]=(attribute_name, attribute_value)
click to toggle source
# File lib/on_form/attributes.rb, line 10 def []=(attribute_name, attribute_value) send("#{attribute_name}=", attribute_value) end
attribute_names()
click to toggle source
# File lib/on_form/attributes.rb, line 22 def attribute_names self.class.exposed_attributes.values.flat_map(&:keys).collect(&:to_s) + self.class.introduced_attribute_types.keys.collect(&:to_s) end
attributes()
click to toggle source
# File lib/on_form/attributes.rb, line 27 def attributes attribute_names.each_with_object({}) do |attribute_name, results| results[attribute_name] = self[attribute_name] end end
attributes=(attributes)
click to toggle source
# File lib/on_form/attributes.rb, line 33 def attributes=(attributes) # match ActiveRecord #attributes= behavior on nil, scalars, etc. if !attributes.respond_to?(:stringify_keys) raise ArgumentError, "When assigning attributes, you must pass a hash as an argument." end multiparameter_attributes = {} attributes.each do |attribute_name, attribute_value| attribute_name = attribute_name.to_s if attribute_name.include?('(') multiparameter_attributes[attribute_name] = attribute_value else write_attribute(attribute_name, attribute_value) end end assign_multiparameter_attributes(multiparameter_attributes) end
read_attribute_for_validation(attribute_name)
click to toggle source
# File lib/on_form/attributes.rb, line 14 def read_attribute_for_validation(attribute_name) send(attribute_name) end
write_attribute(attribute_name, attribute_value)
click to toggle source
# File lib/on_form/attributes.rb, line 18 def write_attribute(attribute_name, attribute_value) send("#{attribute_name}=", attribute_value) end
Private Instance Methods
backing_for_attribute(exposed_name)
click to toggle source
# File lib/on_form/attributes.rb, line 60 def backing_for_attribute(exposed_name) self.class.exposed_attributes.each do |backing_model_name, attribute_mappings| if backing_name = attribute_mappings[exposed_name.to_sym] return [backing_model_instance(backing_model_name), backing_name] end end nil end
backing_model_instance(backing_model_name)
click to toggle source
# File lib/on_form/attributes.rb, line 52 def backing_model_instance(backing_model_name) send(backing_model_name) end
backing_model_instances()
click to toggle source
# File lib/on_form/attributes.rb, line 56 def backing_model_instances self.class.exposed_attributes.keys.collect { |backing_model_name| backing_model_instance(backing_model_name) } end