Class: ServiceCore::FieldSet

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_hObject (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

#inspectObject



17
18
19
# File 'lib/service_core/field_set.rb', line 17

def inspect
  "#<#{self.class.name} #{@to_h.inspect}>"
end