Module: Cucumber::CoreExt::CallIn

Defined in:
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/cucumber/core_ext/proc.rb', line 9

def name
  @name
end

Instance Method Details

#arity2Object



22
23
24
# File 'lib/cucumber/core_ext/proc.rb', line 22

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

#call_in(obj, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/cucumber/core_ext/proc.rb', line 11

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

#file_colon_lineObject



34
35
36
37
38
39
40
# File 'lib/cucumber/core_ext/proc.rb', line 34

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

#methObject



42
43
44
# File 'lib/cucumber/core_ext/proc.rb', line 42

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

#modObject



46
47
48
49
50
51
52
# File 'lib/cucumber/core_ext/proc.rb', line 46

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

#to_backtrace_lineObject



26
27
28
# File 'lib/cucumber/core_ext/proc.rb', line 26

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

#to_comment_lineObject



30
31
32
# File 'lib/cucumber/core_ext/proc.rb', line 30

def to_comment_line
  "# #{file_colon_line}"
end