Class: Trestle::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/hook.rb

Defined Under Namespace

Classes: Set

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={}, &block)
  @name, @options, @block = name, options, block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/trestle/hook.rb', line 3

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/trestle/hook.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/trestle/hook.rb', line 3

def options
  @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 && options == other.options && 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

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
# File 'lib/trestle/hook.rb', line 13

def visible?(context)
  if options[:if]
    context.instance_exec(&options[:if])
  elsif options[:unless]
    !context.instance_exec(&options[:unless])
  else
    true
  end
end