Class: Trestle::Hook
- Inherits:
-
Object
- Object
- Trestle::Hook
- Defined in:
- lib/trestle/hook.rb,
lib/trestle/hook/set.rb,
lib/trestle/hook/helpers.rb
Defined Under Namespace
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, *args) ⇒ 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.
8 9 10 |
# File 'lib/trestle/hook.rb', line 8 def initialize(name, ={}, &block) @name, @options, @block = name, , block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
6 7 8 |
# File 'lib/trestle/hook.rb', line 6 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/trestle/hook.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/trestle/hook.rb', line 6 def @options end |
Instance Method Details
#==(other) ⇒ Object
12 13 14 |
# File 'lib/trestle/hook.rb', line 12 def ==(other) other.is_a?(self.class) && name == other.name && == other. && block == other.block end |
#evaluate(context, *args) ⇒ Object
26 27 28 |
# File 'lib/trestle/hook.rb', line 26 def evaluate(context, *args) context.instance_exec(*args, &block) end |
#visible?(context) ⇒ Boolean
16 17 18 19 20 21 22 23 24 |
# File 'lib/trestle/hook.rb', line 16 def visible?(context) if [:if] context.instance_exec(&[:if]) elsif [:unless] !context.instance_exec(&[:unless]) else true end end |