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, type, options = {}) ⇒ 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=
129 130 131 132 133 134 135 136 |
# File 'lib/virtus/value_object.rb', line 129 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, type, options = {}) ⇒ self
Define an attribute on the receiver
The Attribute will have private writer methods (eg., immutable instances)
and be used in equality/equivalence comparisons
96 97 98 99 100 |
# File 'lib/virtus/value_object.rb', line 96 def attribute(name, type, = {}) equalizer << name [:writer] = :private super 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
115 116 117 118 119 120 121 122 |
# File 'lib/virtus/value_object.rb', line 115 def equalizer @equalizer ||= begin equalizer = Equalizer.new(name || inspect) include equalizer equalizer end end |