Class: Trestle::Hook
- Inherits:
-
Object
- Object
- Trestle::Hook
- Defined in:
- lib/trestle/hook.rb
Defined Under Namespace
Classes: Set
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #evaluate(context) ⇒ Object
-
#initialize(name, options = {}, &block) ⇒ Hook
constructor
A new instance of Hook.
- #visible?(context) ⇒ Boolean
Constructor Details
#initialize(name, options = {}, &block) ⇒ Hook
Returns a new instance of Hook.
5 6 7 |
# File 'lib/trestle/hook.rb', line 5 def initialize(name, ={}, &block) @name, @options, @block = name, , block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/trestle/hook.rb', line 3 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/trestle/hook.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/trestle/hook.rb', line 3 def @options end |
Instance Method Details
#==(other) ⇒ Object
9 10 11 |
# File 'lib/trestle/hook.rb', line 9 def ==(other) other.is_a?(self.class) && name == other.name && == other. && block == other.block end |
#evaluate(context) ⇒ Object
23 24 25 |
# File 'lib/trestle/hook.rb', line 23 def evaluate(context) context.instance_exec(&block) end |
#visible?(context) ⇒ Boolean
13 14 15 16 17 18 19 20 21 |
# File 'lib/trestle/hook.rb', line 13 def visible?(context) if [:if] context.instance_exec(&[:if]) elsif [:unless] !context.instance_exec(&[:unless]) else true end end |