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=
116 117 118 119 120 121 122 123 |
# File 'lib/virtus/value_object.rb', line 116 def allowed_writer_methods @allowed_writer_methods ||= begin allowed_writer_methods = super allowed_writer_methods += attributes.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
83 84 85 86 87 |
# File 'lib/virtus/value_object.rb', line 83 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
102 103 104 105 106 107 108 109 |
# File 'lib/virtus/value_object.rb', line 102 def equalizer @equalizer ||= begin equalizer = Equalizer.new(name || inspect) include equalizer equalizer end end |