Class: Domotics::Core::Setup
- Inherits:
-
BasicObject
- Defined in:
- lib/domotics/core/setup.rb
Constant Summary
collapse
- @@logger =
::Logger.new(::STDERR)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(conf) ⇒ Setup
Returns a new instance of Setup.
14
15
16
17
18
19
|
# File 'lib/domotics/core/setup.rb', line 14
def initialize(conf)
@current_room = {}
@current_device = {}
@groups = []
instance_eval conf, __FILE__, __LINE__
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/domotics/core/setup.rb', line 61
def method_missing(symbol, *args, &block)
if CLASS_MAP[symbol] and name = args.shift
args_hash = args.shift || {}
args_hash[:name] = name
args_hash[:type] = symbol if CLASS_MAP[symbol][0] != :element
args_hash[:logger] = @@logger
__send__(*CLASS_MAP[symbol], args_hash, &block)
else
super
end
end
|
Class Method Details
7
8
9
|
# File 'lib/domotics/core/setup.rb', line 7
def self.logger
@@logger
end
|
.logger=(logger) ⇒ Object
10
11
12
|
# File 'lib/domotics/core/setup.rb', line 10
def self.logger=(logger)
@@logger = logger
end
|
Instance Method Details
#device(klass, args = {}) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/domotics/core/setup.rb', line 41
def device(klass, args = {})
@current_device[:name] = args[:name]
@current_device[:type] = args[:type]
args[:room] = Room[@current_room[:name]]
klass.new(args) unless Device[args[:name]]
yield if ::Kernel.block_given?
@current_device.clear
end
|
#element(klass, args = {}) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/domotics/core/setup.rb', line 50
def element(klass, args = {})
raise "Element must have room" unless @current_room.any?
args[:room] = Room[@current_room[:name]]
args[:room_type] = @current_room[:type]
args[:device] = Device[@current_device[:name]]
args[:device_type] = @current_device[:type]
klass = klass.dup if args[:device_type]
el = klass.new(args) unless Room[@current_room[:name]][args[:name]]
@groups[-1].add_element el if @groups[-1]
end
|
#element_group(args = {}) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/domotics/core/setup.rb', line 21
def element_group(args = {})
raise "Element group must have room" unless @current_room.any?
args[:room] = @current_room[:name]
unless gr = Room[@current_room[:name]][args[:name]]
gr = ElementGroup.new args
@groups[-1].add_element gr if @groups[-1]
end
@groups.push(gr)
yield if ::Kernel.block_given?
@groups.pop
end
|
#room(klass, args = {}) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/domotics/core/setup.rb', line 33
def room(klass, args = {})
@current_room[:name] = args[:name]
@current_room[:type] = args[:type]
klass.new(args) unless Room[args[:name]]
yield if ::Kernel.block_given?
@current_room.clear
end
|