Module: NetRecorder

Defined in:
lib/http.rb,
lib/config.rb,
lib/http_header.rb,
lib/netrecorder.rb

Overview

NetRecorder - the global namespace

Defined Under Namespace

Modules: NetHTTP, NetHTTPHeader Classes: Config

Class Method Summary collapse

Class Method Details

.cache!Object

save the fakes hash to the cash file



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

def self.cache!
  File.open(@@config.cache_file, 'w') {|f| f.write Net::HTTP.fakes.to_yaml}
end

.cache_fileObject

the path to the cache file



13
14
15
# File 'lib/netrecorder.rb', line 13

def self.cache_file
  @@config.cache_file
end

.clear_cache!Object

delete the cache file



46
47
48
49
50
51
# File 'lib/netrecorder.rb', line 46

def self.clear_cache!
  if File.exist?(@@config.cache_file)
    File.delete(@@config.cache_file)
  end
  Net::HTTP.clear_netrecorder_cache!
end

.config {|@@config| ... } ⇒ Object

configure netrecorder

Yields:



26
27
28
29
30
31
32
33
# File 'lib/netrecorder.rb', line 26

def self.config
  @@configured ||= nil
  @@config = Config.new
  yield @@config
  record_net_calls
  clear_cache!      if @@config.clear_cache
  fakeweb           if @@config.fakeweb
end

.fakesObject



17
18
19
20
21
22
23
# File 'lib/netrecorder.rb', line 17

def self.fakes
  if File.exist?(@@config.cache_file)
    File.open(@@config.cache_file, "r") do |f|
      YAML.load(f.read)
    end
  end || []
end

.recording?Boolean

returns true if record_net_calls is set to true in the config

Returns:

  • (Boolean)


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

def self.recording?
  @@config.record_net_calls
end

.register_scope(name) ⇒ Object



53
54
55
# File 'lib/netrecorder.rb', line 53

def self.register_scope(name)
  fakeweb(name)
end

.scopeObject



61
62
63
64
# File 'lib/netrecorder.rb', line 61

def self.scope
  return @@scope if defined?(@@scope) 
  'global'
end

.scope=(name) ⇒ Object



57
58
59
# File 'lib/netrecorder.rb', line 57

def self.scope=(name)
  @@scope = name
end