module Juniter::HasAttributes::ClassMethods
Public Instance Methods
attribute(name, as: nil, required: false, validation: nil, map: nil)
click to toggle source
# File lib/juniter/has_attributes.rb, line 12 def attribute(name, as: nil, required: false, validation: nil, map: nil) attributes << name attribute_aliases[name] = as unless as.nil? attribute_processors[name] = map || ->(value) { value } define_method :"#{name}" do instance_variable_get :"@_#{name}" if instance_variable_defined?(:"@_#{name}") end define_method :"#{name}=" do |value| send validation, value unless validation.nil? instance_variable_set :"@_#{name}", value end end
attribute_aliases()
click to toggle source
# File lib/juniter/has_attributes.rb, line 31 def attribute_aliases @__attribute_aliases ||= {} end
attribute_processors()
click to toggle source
# File lib/juniter/has_attributes.rb, line 35 def attribute_processors @__attribute_processors ||= {} end
attributes()
click to toggle source
# File lib/juniter/has_attributes.rb, line 27 def attributes @__attributes ||= [] end
required_attributes()
click to toggle source
# File lib/juniter/has_attributes.rb, line 39 def required_attributes @__required_attributes ||= [] end