Class: Strict::Accessor::Module
- Inherits:
-
Module
- Object
- Module
- Strict::Accessor::Module
- Defined in:
- lib/strict/accessor/module.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Module
constructor
rubocop:disable Metrics/MethodLength.
-
#inspect ⇒ Object
rubocop:enable Metrics/MethodLength.
Constructor Details
#initialize(configuration) ⇒ Module
rubocop:disable Metrics/MethodLength
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/strict/accessor/module.rb', line 9 def initialize(configuration) super() @configuration = configuration const_set(Strict::Attributes::Class::CONSTANT, configuration) configuration.attributes.each do |attribute| module_eval(<<~RUBY, __FILE__, __LINE__ + 1) def #{attribute.name} # def name #{attribute.instance_variable} # @instance_variable end # end RUBY module_eval(<<~RUBY, __FILE__, __LINE__ + 1) def #{attribute.name}=(value) # def name=(value) attribute = self.class.strict_attributes.named!(:#{attribute.name}) # attribute = self.class.strict_attributes.named!(:name) value = attribute.coerce(value, for_class: self.class) # value = attribute.coerce(value, for_class: self.class) if attribute.valid?(value) # if attribute.valid?(value) #{attribute.instance_variable} = value # @instance_variable = value else # else raise Strict::AssignmentError.new( # raise Strict::AssignmentError.new( assignable_class: self.class, # assignable_class: self.class, invalid_attribute: attribute, # invalid_attribute: attribute, value: value # value: value ) # ) end # end end # end RUBY end end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
6 7 8 |
# File 'lib/strict/accessor/module.rb', line 6 def configuration @configuration end |
Instance Method Details
#inspect ⇒ Object
rubocop:enable Metrics/MethodLength
40 41 42 |
# File 'lib/strict/accessor/module.rb', line 40 def inspect "#<#{self.class} (#{configuration.attributes.map(&:name).join(', ')})>" end |