Class: Cockpit::Scope
- Inherits:
-
Object
show all
- Defined in:
- lib/cockpit/core/scope.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(settings, method, *args, &block) ⇒ Scope
Returns a new instance of Scope.
5
6
7
8
|
# File 'lib/cockpit/core/scope.rb', line 5
def initialize(settings, method, *args, &block)
@settings = settings
_process(method, *args, &block)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
75
76
77
|
# File 'lib/cockpit/core/scope.rb', line 75
def method_missing(method, *args, &block)
_process(method, *args, &block)
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
3
4
5
|
# File 'lib/cockpit/core/scope.rb', line 3
def key
@key
end
|
#settings ⇒ Object
Returns the value of attribute settings.
3
4
5
|
# File 'lib/cockpit/core/scope.rb', line 3
def settings
@settings
end
|
Instance Method Details
#_process(method, *args, &block) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/cockpit/core/scope.rb', line 46
def _process(method, *args, &block)
method = method.to_s
node = method.dup
boolean = !!(node =~ /\?$/)
node.gsub!(/\?/, "") if boolean
set = !!(node =~ /=$/)
node.gsub!("=", "") if set
new_key = "#{key}.#{node}"
return value.send(method) if key && !settings.has_key?(new_key) && value.respond_to?(method)
if key
@key = new_key
else
@key = node
end
if boolean == true
settings.has_key?(key)
elsif set == true
self.value = args.pop
else
self
end
end
|
#blank? ⇒ Boolean
42
43
44
|
# File 'lib/cockpit/core/scope.rb', line 42
def blank?
value.blank?
end
|
#empty? ⇒ Boolean
38
39
40
|
# File 'lib/cockpit/core/scope.rb', line 38
def empty?
value.empty?
end
|
#nil? ⇒ Boolean
34
35
36
|
# File 'lib/cockpit/core/scope.rb', line 34
def nil?
value.nil?
end
|
#to_f ⇒ Object
30
31
32
|
# File 'lib/cockpit/core/scope.rb', line 30
def to_f
value.to_f
end
|
#to_i ⇒ Object
22
23
24
|
# File 'lib/cockpit/core/scope.rb', line 22
def to_i
value.to_i
end
|
#to_s ⇒ Object
26
27
28
|
# File 'lib/cockpit/core/scope.rb', line 26
def to_s
value.to_s
end
|
#value ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/cockpit/core/scope.rb', line 10
def value
if settings[key].nil?
nil
else
JSON.parse(%Q|{"value":#{settings[key]}}|)['value']
end
end
|
#value=(x) ⇒ Object
18
19
20
|
# File 'lib/cockpit/core/scope.rb', line 18
def value=(x)
settings[key] = x
end
|