Class: Prefab::Context::NamedContext

Inherits:
Object
  • Object
show all
Defined in:
lib/prefab/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#keyObject



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_hObject



25
26
27
# File 'lib/prefab/context.rb', line 25

def to_h
  @hash
end

#to_protoObject



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