module SimpleParams::HasAttributes::ClassMethods
Public Instance Methods
defined_attributes()
click to toggle source
# File lib/simple_params/concerns/has_attributes.rb, line 12 def defined_attributes @define_attributes ||= {} end
Private Instance Methods
define_attribute(name, opts = {})
click to toggle source
# File lib/simple_params/concerns/has_attributes.rb, line 17 def define_attribute(name, opts = {}) opts[:type] ||= :string defined_attributes[name.to_sym] = opts attr_accessor "#{name}_attribute" define_method("#{name}") do attribute = send("#{name}_attribute") attribute.send("value") end define_method("raw_#{name}") do attribute = send("#{name}_attribute") attribute.send("raw_value") end define_method("#{name}=") do |val| attribute = send("#{name}_attribute") attribute.send("value=", val) end end