Class: Livetext::VariableManager
- Inherits:
-
Object
- Object
- Livetext::VariableManager
show all
- Defined in:
- lib/livetext/variable_manager.rb
Overview
Variable Manager - Centralized variable handling for Livetext
Instance Method Summary
collapse
Constructor Details
Returns a new instance of VariableManager.
3
4
5
6
7
|
# File 'lib/livetext/variable_manager.rb', line 3
def initialize(parent)
@parent = parent
@variables = Livetext::Variables.new
initialize_default_variables
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Enable live.vars.myvar syntax
44
45
46
47
48
49
50
|
# File 'lib/livetext/variable_manager.rb', line 44
def method_missing(name, *args)
if args.empty?
@variables[name.to_sym] || "[#{name} is undefined]"
else
super
end
end
|
Instance Method Details
17
18
19
|
# File 'lib/livetext/variable_manager.rb', line 17
def [](name)
@variables[name]
end
|
#exists?(name) ⇒ Boolean
27
28
29
|
# File 'lib/livetext/variable_manager.rb', line 27
def exists?(name)
@variables.exists?(name)
end
|
#get(name) ⇒ Object
13
14
15
|
# File 'lib/livetext/variable_manager.rb', line 13
def get(name)
@variables.get(name)
end
|
31
32
33
|
# File 'lib/livetext/variable_manager.rb', line 31
def list
@variables.inspect
end
|
#replace(vars) ⇒ Object
39
40
41
|
# File 'lib/livetext/variable_manager.rb', line 39
def replace(vars)
@variables = Livetext::Variables.new(vars)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
52
53
54
|
# File 'lib/livetext/variable_manager.rb', line 52
def respond_to_missing?(name, include_private = false)
true
end
|
#set(name, value) ⇒ Object
9
10
11
|
# File 'lib/livetext/variable_manager.rb', line 9
def set(name, value)
@variables.set(name, value)
end
|
#set_multiple(pairs) ⇒ Object
21
22
23
24
25
|
# File 'lib/livetext/variable_manager.rb', line 21
def set_multiple(pairs)
pairs.each do |name, value|
set(name, value)
end
end
|
35
36
37
|
# File 'lib/livetext/variable_manager.rb', line 35
def to_h
@variables.to_h
end
|