Module: VcrCable

Extended by:
VcrCable
Included in:
VcrCable
Defined in:
lib/vcr_cable.rb,
lib/vcr_cable/railtie.rb,
lib/vcr_cable/version.rb

Defined Under Namespace

Classes: InvalidMockingLibraryError, Railtie

Constant Summary collapse

CONFIG_FILE =
'vcr_cable.yml'
DEFAULT_CONFIG =
{
  'development' => {
    'cassette_library_dir' => 'development_cassettes',
    'allow_http_connections_when_no_cassette' => true,
    'allow_playback_repeats' => false
  }
}
VERSION =
'1.0.0'

Instance Method Summary collapse

Instance Method Details

#configObject



29
30
31
# File 'lib/vcr_cable.rb', line 29

def config
  @config ||= default_config.merge(local_config).merge(env_config)
end

#configure_vcrObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vcr_cable.rb', line 17

def configure_vcr
  VCR.configure do |c|
    c.hook_into config['hook_into']
    c.default_cassette_options = {
       :erb => config['enable_erb'],
       :allow_playback_repeats => config['allow_playback_repeats']
    }
    c.cassette_library_dir = config['cassette_library_dir']
    c.allow_http_connections_when_no_cassette = config['allow_http_connections_when_no_cassette']
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/vcr_cable.rb', line 33

def enabled?
  config.present? && config['enable_vcr_cable']
end

#enabled_by_env?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/vcr_cable.rb', line 37

def enabled_by_env?
  %w(true 1).include?(ENV['ENABLE_VCR_CABLE']).presence
end

#reset_configObject



41
42
43
44
45
# File 'lib/vcr_cable.rb', line 41

def reset_config
  %w[local_config config_file default_config env_config config].each do |name|
    instance_variable_set "@#{name}", nil
  end
end