Module: Cucumber::CoreExt::CallIn

Defined in:
lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb

Overview

Proc extension that allows a proc to be called in the context of any object. Also makes it possible to tack a name onto a Proc.

Constant Summary collapse

PROC_PATTERN =
/[\d\w]+@(.*):(.*)>/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



40
41
42
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 40

def name
  @name
end

Instance Method Details

#arity2Object



52
53
54
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 52

def arity2
  arity == -1 ? 0 : arity
end

#call_in(obj, *args) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 42

def call_in(obj, *args)
  obj.extend(mod)
  if self != StepMother::PENDING && args.length != arity2
    # We have to manually raise when the block has arity -1 (no pipes)
    raise ArityMismatchError.new("expected #{arity2} block argument(s), got #{args.length}")
  else
    obj.__send__(meth, *args)
  end
end

#file_colon_lineObject



20
21
22
23
24
25
26
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 20

def file_colon_line
  path, line = *to_s.match(PROC_PATTERN)[1..2]
  path = File.expand_path(path)
  pwd = Dir.pwd
  path = path[pwd.length+1..-1]
  "#{path}:#{line}"
end

#methObject



56
57
58
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 56

def meth
  @meth ||= "__cucumber_#{object_id}"
end

#modObject



60
61
62
63
64
65
66
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 60

def mod
  p = self
  m = meth
  @mod ||= Module.new do
    define_method(m, &p)
  end
end

#to_backtrace_lineObject



12
13
14
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 12

def to_backtrace_line
  "#{file_colon_line}:in `#{name}'"
end

#to_comment_lineObject



16
17
18
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/core_ext/proc.rb', line 16

def to_comment_line
  "# #{file_colon_line}"
end