Class: SPV::DSL::InitialAdjuster

Inherits:
Object
  • Object
show all
Defined in:
lib/site_prism_vcr/dsl/initial_adjuster.rb

Overview

This class provides DSL which is used while defining fixtures and applying them.

Direct Known Subclasses

Adjuster

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ InitialAdjuster

Returns a new instance of InitialAdjuster.



6
7
8
9
10
# File 'lib/site_prism_vcr/dsl/initial_adjuster.rb', line 6

def initialize(options)
  @options          = options
  @tmp_keeper       = Fixtures::TmpKeeper.new(@options)
  @fixtures_handler = Fixtures::Handler.new(@options)
end

Instance Method Details

#fixtures(list) ⇒ void

This method returns an undefined value.

Defines fixtures which will be inserted into VCR.

Parameters:

  • list (Array<String>)

    List of fixtures.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/site_prism_vcr/dsl/initial_adjuster.rb', line 19

def fixtures(list)
  prepared_fixtures = @fixtures_handler.handle_raw(
    list,
    [
      Fixtures::Modifiers::ShortcutPath.new(@options),
      Fixtures::Modifiers::RelativePath.new(@options)
    ]
  )

  @tmp_keeper.add_fixtures(prepared_fixtures)
end

#home_path(path) ⇒ void

This method returns an undefined value.

Defines a home path to fixtures. Later this path can be used for defining fixtures.

Example:

home_path 'cassettes/cars/ford'
fixtures['~/car']

Parameters:

  • path (String)

    Path to fixtures.



43
44
45
# File 'lib/site_prism_vcr/dsl/initial_adjuster.rb', line 43

def home_path(path)
  @options.add_shortcut_path('~', path)
end

#path(path, fixture_names) ⇒ void

This method returns an undefined value.

Applies a given path to list of fixtures and defines those fixtures to be inserted into VCR.

Parameters:

  • path (String)

    Path to fixtures.

  • fixture_names (Array<String>)

    List of fixtures.

Raises:

  • (ArgumentError)

    If any of fixture names has path to a home directory.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/site_prism_vcr/dsl/initial_adjuster.rb', line 75

def path(path, fixture_names)
  options_with_path  = OptionsWithPath.new(@options)
  options_with_path.path = path

  path_modifier      = Fixtures::Modifiers::Path.new(options_with_path)
  home_path_modifier = Fixtures::Modifiers::ShortcutPath.new(options_with_path)

  prepared_fixtures = @fixtures_handler.handle_raw(
    fixture_names,
    [
      path_modifier,
      home_path_modifier
    ]
  )

  @tmp_keeper.add_fixtures(prepared_fixtures)
end

#prepare_fixturesSPV::Fixtures

Returns set of prepared fixtures.

Returns:



115
116
117
# File 'lib/site_prism_vcr/dsl/initial_adjuster.rb', line 115

def prepare_fixtures
  Fixtures.new(@tmp_keeper.fixtures)
end

#shortcut_path(name, path) ⇒ void

This method returns an undefined value.

Defines a shortcut path to fixtures. Later this path can be used for defining fixtures.

Example:

shortcut_path 'ford', 'cassettes/cars/ford'
fixtures[':ford/car']

Parameters:

  • name (String)

    Shortcut name to be used while defining a path to fixtures..

  • path (String)

    Path to fixtures.



60
61
62
# File 'lib/site_prism_vcr/dsl/initial_adjuster.rb', line 60

def shortcut_path(name, path)
  @options.add_shortcut_path(name, path)
end

#waiter(waiter_options = nil) { ... } ⇒ void

This method returns an undefined value.

Defines a waiter which will be used for waiting until all HTTP interactions have finished.

Parameters:

  • options (Hash, nil)

    Options which allows to change behavior of a waiter.

Yields:

  • Block to be used as a waiter.



105
106
107
108
# File 'lib/site_prism_vcr/dsl/initial_adjuster.rb', line 105

def waiter(waiter_options = nil, &block)
  @options.waiter         = block
  @options.waiter_options = waiter_options
end