Class: Cucumber::RbSupport::RbTransform

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/rb_support/rb_transform.rb

Overview

A Ruby Transform holds a Regexp and a Proc, and is created by calling Transform in the <tt>support ruby files. See also RbDsl.

Example:

Transform /^(\d+) cucumbers$/ do |cucumbers_string|
  cucumbers_string.to_i
end

Defined Under Namespace

Classes: MissingProc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rb_language, pattern, proc) ⇒ RbTransform

Returns a new instance of RbTransform.

Raises:



22
23
24
25
# File 'lib/cucumber/rb_support/rb_transform.rb', line 22

def initialize(rb_language, pattern, proc)
  raise MissingProc if proc.nil? || proc.arity < 1
  @rb_language, @regexp, @proc = rb_language, Regexp.new(pattern), proc        
end

Instance Attribute Details

#procObject (readonly)

Returns the value of attribute proc.



20
21
22
# File 'lib/cucumber/rb_support/rb_transform.rb', line 20

def proc
  @proc
end

#regexpObject (readonly)

Returns the value of attribute regexp.



20
21
22
# File 'lib/cucumber/rb_support/rb_transform.rb', line 20

def regexp
  @regexp
end

Instance Method Details

#invoke(arg) ⇒ Object



27
28
29
30
31
32
# File 'lib/cucumber/rb_support/rb_transform.rb', line 27

def invoke(arg)
  if matched = regexp.match(arg)
    args = Array(matched.captures.empty? ? arg : matched.captures)
    @rb_language.current_world.cucumber_instance_exec(true, regexp.inspect, *args, &@proc)
  end        
end