Class: Trestle::Hook

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

Defined Under Namespace

Modules: Helpers Classes: Set

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/trestle/hook.rb', line 6

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/trestle/hook.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/trestle/hook.rb', line 6

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

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
# File 'lib/trestle/hook.rb', line 16

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