Module: Virtus::ValueObject::ClassMethods
- Defined in:
- lib/virtus/value_object.rb
Instance Method Summary collapse
-
#allowed_writer_methods ⇒ Set
private
The list of writer methods that can be mass-assigned to in #attributes=.
-
#attribute(name, *args) ⇒ self
Define an attribute on the receiver.
-
#equalizer ⇒ Equalizer
Define and include a module that provides Value Object semantics.
Instance Method Details
#allowed_writer_methods ⇒ Set
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The list of writer methods that can be mass-assigned to in #attributes=
130 131 132 133 134 135 136 137 |
# File 'lib/virtus/value_object.rb', line 130 def allowed_writer_methods @allowed_writer_methods ||= begin allowed_writer_methods = super allowed_writer_methods += attribute_set.map{|attr| "#{attr.name}="} allowed_writer_methods.to_set.freeze end end |
#attribute(name, *args) ⇒ self
Define an attribute on the receiver
The Attribute will have private writer methods (eg., immutable instances)
and be used in equality/equivalence comparisons
97 98 99 100 101 |
# File 'lib/virtus/value_object.rb', line 97 def attribute(name, *args) equalizer << name = args.last.kind_of?(Hash) ? args.pop : {} super name, *args << .merge(:writer => :private) end |
#equalizer ⇒ Equalizer
Define and include a module that provides Value Object semantics
Included module will have #inspect, #eql?, #== and #hash methods whose definition is based on the keys argument
116 117 118 119 120 121 122 123 |
# File 'lib/virtus/value_object.rb', line 116 def equalizer @equalizer ||= begin equalizer = Equalizer.new(name || inspect) include equalizer equalizer end end |