Class: ServiceCore::FieldSet
- Inherits:
-
Object
- Object
- ServiceCore::FieldSet
- Defined in:
- lib/service_core/field_set.rb
Overview
Immutable snapshot of a service’s declared fields and their values at #initialize time. Each symbol key is exposed as a real method; call #to_h for the raw snapshot Hash.
Instance Attribute Summary collapse
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
Instance Method Summary collapse
-
#initialize(values = {}) ⇒ FieldSet
constructor
A new instance of FieldSet.
- #inspect ⇒ Object
Constructor Details
#initialize(values = {}) ⇒ FieldSet
Returns a new instance of FieldSet.
8 9 10 11 12 13 14 15 |
# File 'lib/service_core/field_set.rb', line 8 def initialize(values = {}) @to_h = values.to_h.freeze @to_h.each_key do |name| next unless name.is_a?(Symbol) define_singleton_method(name) { @to_h[name] } end end |
Instance Attribute Details
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
6 7 8 |
# File 'lib/service_core/field_set.rb', line 6 def to_h @to_h end |
Instance Method Details
#inspect ⇒ Object
17 18 19 |
# File 'lib/service_core/field_set.rb', line 17 def inspect "#<#{self.class.name} #{@to_h.inspect}>" end |