Class: Prefab::Context::NamedContext
- Inherits:
-
Object
- Object
- Prefab::Context::NamedContext
- Defined in:
- lib/prefab/context.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #get(parts) ⇒ Object
-
#initialize(name, hash) ⇒ NamedContext
constructor
A new instance of NamedContext.
- #key ⇒ Object
- #merge!(other) ⇒ Object
- #to_h ⇒ Object
- #to_proto ⇒ Object
Constructor Details
#initialize(name, hash) ⇒ NamedContext
Returns a new instance of NamedContext.
10 11 12 13 14 15 |
# File 'lib/prefab/context.rb', line 10 def initialize(name, hash) @hash = {} @name = name.to_s merge!(hash) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/prefab/context.rb', line 8 def name @name end |
Instance Method Details
#get(parts) ⇒ Object
17 18 19 |
# File 'lib/prefab/context.rb', line 17 def get(parts) @hash[parts] end |
#key ⇒ Object
29 30 31 |
# File 'lib/prefab/context.rb', line 29 def key "#{@name}:#{get('key')}" end |
#merge!(other) ⇒ Object
21 22 23 |
# File 'lib/prefab/context.rb', line 21 def merge!(other) @hash = @hash.merge(other.transform_keys(&:to_s)) end |
#to_h ⇒ Object
25 26 27 |
# File 'lib/prefab/context.rb', line 25 def to_h @hash end |
#to_proto ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/prefab/context.rb', line 33 def to_proto PrefabProto::Context.new( type: name, values: to_h.transform_values do |value| ConfigValueWrapper.wrap(value) end ) end |