Class: Webpoke::Config
- Inherits:
-
Object
- Object
- Webpoke::Config
- Defined in:
- lib/Webpoke/Config.rb
Constant Summary collapse
- @@valid_parse_types =
['json']
Instance Method Summary collapse
- #beforeSend(callable = nil) ⇒ Object
-
#initialize(&block) ⇒ Config
constructor
A new instance of Config.
- #on_failure(&block) ⇒ Object
- #parse(type = nil) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/Webpoke/Config.rb', line 7 def initialize(&block) @base = ''; @headers = {} @parse = {input:nil, output:nil} if (block_given?) instance_eval(&block); end @format = @format || 'stdout' end |
Instance Method Details
#beforeSend(callable = nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/Webpoke/Config.rb', line 28 def beforeSend callable=nil if callable raise new Webpoke::ConfigError("Can't register your beforeSend callable because, well, it isn't callable") if !callable.respond_to? :call @beforeSend = callable else @beforeSend end end |
#on_failure(&block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/Webpoke/Config.rb', line 20 def on_failure(&block) if (block_given?) @on_failure = block else @on_failure end end |
#parse(type = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/Webpoke/Config.rb', line 37 def parse type=nil if (type) case type when String raise new Webpoke::ConfigError("I don't know how to parse [#{type}] responses yet :/") unless @@valid_parse_types.include? type @parse = { output: lambda {|d| JSON.parse(d, symbolize_names: true)}, input: lambda {|d| d.to_json } } when Hash @parse = type end else @parse end end |