class NOMS::HttpClient
Public Class Methods
mock!(datafile=nil)
click to toggle source
# File lib/noms/httpclient.rb, line 83 def self.mock!(datafile=nil) @@mocked = true @@mockdata = datafile end
mockery()
click to toggle source
# File lib/noms/httpclient.rb, line 88 def self.mockery NOMS::HttpClient::RestMock end
new(opt)
click to toggle source
# File lib/noms/httpclient.rb, line 92 def initialize(opt) @opt = opt @delegate = (@@mocked ? self.class.mockery.new(self) : NOMS::HttpClient::Real.new(self)) end
Public Instance Methods
allow_partial_updates()
click to toggle source
Used mostly for mocking behavior
# File lib/noms/httpclient.rb, line 130 def allow_partial_updates # Replace during PUT false end
allow_put_to_create()
click to toggle source
# File lib/noms/httpclient.rb, line 135 def allow_put_to_create true end
config_key()
click to toggle source
# File lib/noms/httpclient.rb, line 106 def config_key 'httpclient' end
dbg(msg)
click to toggle source
# File lib/noms/httpclient.rb, line 147 def dbg(msg) if @opt.has_key? 'debug' and @opt['debug'] > 1 puts "DBG(#{self.class}): #{msg}" end end
default_content_type()
click to toggle source
# File lib/noms/httpclient.rb, line 139 def default_content_type 'application/json' end
handle_mock(method, url, opt)
click to toggle source
# File lib/noms/httpclient.rb, line 102 def handle_mock(method, url, opt) false end
ignore_content_type()
click to toggle source
# File lib/noms/httpclient.rb, line 143 def ignore_content_type false end
ltrim(s, c='/')
click to toggle source
# File lib/noms/httpclient.rb, line 164 def ltrim(s, c='/') trim(s, c, :left) end
method_missing(meth, *args, &block)
click to toggle source
# File lib/noms/httpclient.rb, line 172 def method_missing(meth, *args, &block) @delegate.send(meth, *args, &block) end
myconfig(key=nil)
click to toggle source
# File lib/noms/httpclient.rb, line 110 def myconfig(key=nil) unless @opt.has_key? config_key and @opt[config_key] raise NOMS::Error::Config, "Configuration provided to #{self.class} doesn't have a '#{config_key}' key" end cfg = @opt[config_key] if key unless cfg.has_key? key msg = "#{config_key} configuration doesn't have a '#{key}' property" msg += " (#{@opt[config_key].inspect})" raise NOMS::Error::Config, msg end cfg[key] else cfg end end
opt()
click to toggle source
# File lib/noms/httpclient.rb, line 98 def opt @opt end
rtrim(s, c='/')
click to toggle source
# File lib/noms/httpclient.rb, line 168 def rtrim(s, c='/') trim(s, c, :right) end
trim(s, c='/', dir=:both)
click to toggle source
# File lib/noms/httpclient.rb, line 153 def trim(s, c='/', dir=:both) case dir when :both trim(trim(s, c, :right), c, :left) when :right s.sub(Regexp.new(c + '+/'), '') when :left s.sub(Regexp.new('^' + c + '+'), '') end end