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
# File 'lib/prefab/context.rb', line 10

def initialize(name, hash)
  @name = name.to_s
  @hash = hash.transform_keys(&:to_s)
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

#keyObject



19
20
21
# File 'lib/prefab/context.rb', line 19

def key
  "#{@name}:#{@hash['key']}"
end

#to_hObject



15
16
17
# File 'lib/prefab/context.rb', line 15

def to_h
  @hash
end

#to_protoObject



23
24
25
26
27
28
29
30
# File 'lib/prefab/context.rb', line 23

def to_proto
  PrefabProto::Context.new(
    type: name,
    values: @hash.transform_values do |value|
      ConfigValueWrapper.wrap(value)
    end
  )
end