Class: Graft::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/graft/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, opts = {}, &block) ⇒ Callback

NOTE: opts is not used in the current implementation



8
9
10
11
12
13
# File 'lib/graft/callback.rb', line 8

def initialize(name = nil, opts = {}, &block)
  @name = name
  @opts = opts
  @block = block
  @enabled = true
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/graft/callback.rb', line 5

def name
  @name
end

Instance Method Details

#call(*args, **kwargs, &block) ⇒ Object



16
17
18
19
20
# File 'lib/graft/callback.rb', line 16

def call(*args, &block)
  return unless enabled?

  @block.call(*args, &block)
end

#disableObject



29
30
31
# File 'lib/graft/callback.rb', line 29

def disable
  @enabled = false
end

#enableObject



33
34
35
# File 'lib/graft/callback.rb', line 33

def enable
  @enabled = true
end

#enabled?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/graft/callback.rb', line 37

def enabled?
  @enabled
end