Class: KuberKit::Core::ContextHelper::ContextVars
- Inherits:
-
Object
- Object
- KuberKit::Core::ContextHelper::ContextVars
show all
- Defined in:
- lib/kuber_kit/core/context_helper/context_vars.rb
Constant Summary
collapse
- BuildArgUndefined =
Class.new(KuberKit::Error)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context_vars, parent_name = nil, parent = nil) ⇒ ContextVars
Returns a new instance of ContextVars.
6
7
8
9
10
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 6
def initialize(context_vars, parent_name = nil, parent = nil)
@context_vars = context_vars
@parent_name = parent_name
@parent = parent
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 27
def method_missing(name, *args)
if args.size > 0
raise ArgumentError.new("context args does not accept any arguments")
end
read(name)
end
|
Instance Attribute Details
Returns the value of attribute parent.
2
3
4
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 2
def parent
@parent
end
|
#parent_name ⇒ Object
Returns the value of attribute parent_name.
2
3
4
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 2
def parent_name
@parent_name
end
|
Instance Method Details
#get_variable_value(variable_name) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 43
def get_variable_value(variable_name)
value = @context_vars.fetch(variable_name) do
raise(BuildArgUndefined, "build arg '#{format_arg(variable_name)}' is not defined, available args: #{@context_vars.inspect}")
end
if value.is_a?(Hash)
return self.class.new(value, variable_name, self)
end
value
end
|
#read(*variable_names) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 12
def read(*variable_names)
result = self
variable_names.each do |var|
result = result.get_variable_value(var)
end
result
end
|
35
36
37
38
39
40
41
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 35
def to_h
if @context_vars.is_a?(Hash)
return @context_vars
else
return {value: @context_vars}
end
end
|
#variable_defined?(*variable_names) ⇒ Boolean
20
21
22
23
24
25
|
# File 'lib/kuber_kit/core/context_helper/context_vars.rb', line 20
def variable_defined?(*variable_names)
read(*variable_names)
return true
rescue BuildArgUndefined
return false
end
|