Class: SPV::Fixture

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

Overview

Keeps a path to a fixture and options which should be passed to Vcr while inserting a cassette

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, vcr_options = {}) ⇒ Fixture

Returns a new instance of Fixture.



9
10
11
12
13
14
15
# File 'lib/site_prism_vcr/fixture.rb', line 9

def initialize(name, vcr_options = {})
  path = Pathname.new(name)

  @fixture_name = path.basename
  @path         = path.dirname
  @options      = vcr_options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/site_prism_vcr/fixture.rb', line 7

def options
  @options
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/site_prism_vcr/fixture.rb', line 7

def path
  @path
end

Instance Method Details

#clean_nameObject

Returns a name without a link to a home path



41
42
43
# File 'lib/site_prism_vcr/fixture.rb', line 41

def clean_name
  @fixture_name.to_path
end

#nameObject



17
18
19
# File 'lib/site_prism_vcr/fixture.rb', line 17

def name
  (self.path + @fixture_name).to_path
end

#prepend_path(val) ⇒ Object



25
26
27
# File 'lib/site_prism_vcr/fixture.rb', line 25

def prepend_path(val)
  self.path = Pathname.new(val) + self.path
end

#set_home_path(path_to) ⇒ Object



29
30
31
32
33
34
# File 'lib/site_prism_vcr/fixture.rb', line 29

def set_home_path(path_to)
  self.path = self.path.to_path.gsub(
    /\A(\:#{self.shortcut_path}\/|:#{self.shortcut_path}|\~\/|\~)/,
    path_to
  )
end

#shortcut_pathObject



36
37
38
# File 'lib/site_prism_vcr/fixture.rb', line 36

def shortcut_path
  res = (self.name.match(/:(\w+)\//) || self.name.match(/(~)\//)) and res[1]
end