module FormAttribute::InstanceMethods
Public Instance Methods
inspect()
click to toggle source
# File lib/form_attribute.rb, line 69 def inspect attrs = attributes.map { |name| "#{name}: #{read_attribute(name).inspect}" }.join(', ') "#<#{self.class} #{attrs}>" end
Private Instance Methods
attributes()
click to toggle source
# File lib/form_attribute.rb, line 92 def attributes self.class.attributes end
default_for(name)
click to toggle source
# File lib/form_attribute.rb, line 100 def default_for(name) self.class.default_for(name) end
matching_type_for(name, value)
click to toggle source
# File lib/form_attribute.rb, line 96 def matching_type_for(name, value) self.class.matching_type_for(name, value) end
read_attribute(name)
click to toggle source
# File lib/form_attribute.rb, line 85 def read_attribute(name) raise UnknownAttributeName, name unless attributes.include? name value = instance_variable_get("@#{name}") value || default_for(name) end
write_attribute(name, value)
click to toggle source
# File lib/form_attribute.rb, line 80 def write_attribute(name, value) matching_type_for(name, value) instance_variable_set("@#{name}", value) end
write_many(**attributes)
click to toggle source
# File lib/form_attribute.rb, line 76 def write_many(**attributes) attributes.each { |name, value| write_attribute(name, value) } end