Class: Glimmer::Util::ProcTracker

Inherits:
Proc
  • Object
show all
Defined in:
lib/glimmer/util/proc_tracker.rb

Overview

Decorator that provides tracking facilities for Ruby procs, tracking owner (string), invoked_form method name (symbol/string), and called? (boolean)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proc = nil, owner: nil, invoked_from: nil, &block) ⇒ ProcTracker

Returns a new instance of ProcTracker.



30
31
32
33
34
# File 'lib/glimmer/util/proc_tracker.rb', line 30

def initialize(proc = nil, owner: nil, invoked_from: nil, &block)
  super(proc || block)
  @owner = owner
  @invoked_from = invoked_from
end

Instance Attribute Details

#invoked_fromObject (readonly)

Returns the value of attribute invoked_from.



28
29
30
# File 'lib/glimmer/util/proc_tracker.rb', line 28

def invoked_from
  @invoked_from
end

#ownerObject (readonly)

Returns the value of attribute owner.



28
29
30
# File 'lib/glimmer/util/proc_tracker.rb', line 28

def owner
  @owner
end

Instance Method Details

#call(*args) ⇒ Object



36
37
38
39
# File 'lib/glimmer/util/proc_tracker.rb', line 36

def call(*args)
  __getobj__.call(*args)
  @called = true
end

#called?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/glimmer/util/proc_tracker.rb', line 41

def called?
  !!@called
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/glimmer/util/proc_tracker.rb', line 45

def respond_to?(method_name, include_private = false)
  %w[owner invoked_from called?].include?(method_name.to_s) || super(method_name, include_private)
end