Class: Chanko::ActiveIf
- Inherits:
-
Object
show all
- Defined in:
- lib/chanko/active_if.rb
Defined Under Namespace
Classes: Any, Block, NoConditionFound, None
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*conditions, &block) ⇒ ActiveIf
Returns a new instance of ActiveIf.
31
32
33
34
35
36
37
38
|
# File 'lib/chanko/active_if.rb', line 31
def initialize(*conditions, &block)
@options = conditions.
unless @options.empty?
warn "options in ActiveIf#new are deprecated and are never used at #{caller[0]}"
end
@conditions = conditions
@block = block
end
|
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
24
25
26
|
# File 'lib/chanko/active_if.rb', line 24
def conditions
@conditions
end
|
Class Method Details
.clear ⇒ Object
19
20
21
|
# File 'lib/chanko/active_if.rb', line 19
def clear
definitions.clear
end
|
.define(label, &block) ⇒ Object
7
8
9
|
# File 'lib/chanko/active_if.rb', line 7
def define(label, &block)
definitions[label] = block
end
|
.definitions ⇒ Object
15
16
17
|
# File 'lib/chanko/active_if.rb', line 15
def definitions
@definitions ||= {}
end
|
.find(label) ⇒ Object
11
12
13
|
# File 'lib/chanko/active_if.rb', line 11
def find(label)
definitions[label]
end
|
Instance Method Details
#active?(context, options = {}) ⇒ Boolean
40
41
42
|
# File 'lib/chanko/active_if.rb', line 40
def active?(context, options = {})
blocks.all? {|block| block.call(context, options) }
end
|
#blocks ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/chanko/active_if.rb', line 44
def blocks
@blocks ||= begin
conditions.map do |condition|
Block.new(condition)
end << @block
end.compact
end
|
#options ⇒ Object
remains just for backward compatibility
26
27
28
29
|
# File 'lib/chanko/active_if.rb', line 26
def options warn "ActiveIf#options is deprecated and is never used at #{caller[0]}"
@options
end
|