Class: Lomic::Rule
Instance Method Summary
collapse
Methods inherited from LomicBase
className, #className, new_resource, new_var, resource, var
Constructor Details
#initialize(number) ⇒ Rule
Returns a new instance of Rule.
4
5
6
7
|
# File 'lib/lomic/Rule.rb', line 4
def initialize(number)
@number = number
@event_bag = {} end
|
Instance Method Details
#event(event_name, options = {}, &block) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/lomic/Rule.rb', line 10
def event(event_name, options={}, &block)
options[:priority] ||= 5
options[:name] = event_name
options[:block] = block
event = Event.new(options)
if @event_bag[event_name].nil?
@event_bag[event_name] = [event]
else
arr = @event_bag[event_name]
i = 0
arr.each do |e|
if event.priority > e.priority
arr.insert(i,event)
break
elsif i == arr.size-1
arr.insert(i+1,event)
break
end
i += 1
end
end
end
|
#event_bag ⇒ Object
35
36
37
|
# File 'lib/lomic/Rule.rb', line 35
def event_bag
@event_bag
end
|
#inspect ⇒ Object
39
40
41
|
# File 'lib/lomic/Rule.rb', line 39
def inspect
"Rule #{@number}: #{@event_bag.inspect}"
end
|