Class: Cucumber::Distrib::Events::StepMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/distrib/events.rb

Overview

PORO wrapper of corresponding cucumber event for safe transportation to Leader over DRb.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step_match) ⇒ StepMatch

Returns a new instance of StepMatch.



286
287
288
289
290
291
# File 'lib/cucumber/distrib/events.rb', line 286

def initialize(step_match)
  @step_definition = StepDefinition.new step_match.step_definition
  @step_arguments = step_match.step_arguments.map { |sa| StepArgument.new sa }
  @location = step_match.step_definition.location
  @name_to_match = step_match.step_definition.to_envelope.step_definition.pattern.source.to_s
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



284
285
286
# File 'lib/cucumber/distrib/events.rb', line 284

def location
  @location
end

#step_argumentsObject (readonly)

Returns the value of attribute step_arguments.



284
285
286
# File 'lib/cucumber/distrib/events.rb', line 284

def step_arguments
  @step_arguments
end

#step_definitionObject (readonly)

Returns the value of attribute step_definition.



284
285
286
# File 'lib/cucumber/distrib/events.rb', line 284

def step_definition
  @step_definition
end

Instance Method Details

#format_args(format = ->(a) { a }, &proc) ⇒ Object



293
294
295
# File 'lib/cucumber/distrib/events.rb', line 293

def format_args(format = ->(a) { a }, &proc)
  replace_arguments(@name_to_match, @step_arguments, format, &proc)
end

#replace_arguments(string, step_arguments, format) ⇒ Object

rubocop:disable Metrics/MethodLength



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/cucumber/distrib/events.rb', line 297

def replace_arguments(string, step_arguments, format) # rubocop:disable Metrics/MethodLength
  s = string.dup

  step_arguments.each do |step_argument|
    group = step_argument.group
    next if group.value.nil?

    replacement = if block_given?
                    yield(group.value)
                  elsif format.instance_of?(Proc)
                    format.call(group.value)
                  else
                    format % group.value
                  end

    s.sub!(/\{[^}]+\}/, replacement)
  end

  s
end