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
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #arity2 ⇒ Object
- #call_in(obj, *args) ⇒ Object
- #file_colon_line ⇒ Object
- #meth ⇒ Object
- #mod ⇒ Object
- #to_backtrace_line ⇒ Object
- #to_comment_line ⇒ Object
Instance Attribute Details
#name ⇒ Object
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
#arity2 ⇒ Object
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_line ⇒ Object
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.(path) pwd = Dir.pwd path = path[pwd.length+1..-1] "#{path}:#{line}" end |
#meth ⇒ Object
42 43 44 |
# File 'lib/cucumber/core_ext/proc.rb', line 42 def meth @meth ||= "__cucumber_#{object_id}" end |
#mod ⇒ Object
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_line ⇒ Object
26 27 28 |
# File 'lib/cucumber/core_ext/proc.rb', line 26 def to_backtrace_line "#{file_colon_line}:in `#{name}'" end |
#to_comment_line ⇒ Object
30 31 32 |
# File 'lib/cucumber/core_ext/proc.rb', line 30 def to_comment_line "# #{file_colon_line}" end |