Class: Sinew::Main
Instance Attribute Summary collapse
-
#request_count ⇒ Object
readonly
Returns the value of attribute request_count.
-
#request_tm ⇒ Object
readonly
Returns the value of attribute request_tm.
-
#runtime_options ⇒ Object
readonly
Returns the value of attribute runtime_options.
Instance Method Summary collapse
-
#cache ⇒ Object
http requests and caching.
- #dsl ⇒ Object
- #http(method, url, options = {}) ⇒ Object
-
#initialize(options) ⇒ Main
constructor
A new instance of Main.
-
#output ⇒ Object
output.
- #quiet? ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Main
Returns a new instance of Main.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sinew/main.rb', line 11 def initialize() super() # init @runtime_options = RuntimeOptions.new @request_tm = Time.at(0) @request_count = 0 if [:proxy] addr, port = [:proxy].split(':') .[:http_proxyaddr] = addr .[:http_proxyport] = port || 80 end end |
Instance Attribute Details
#request_count ⇒ Object (readonly)
Returns the value of attribute request_count.
9 10 11 |
# File 'lib/sinew/main.rb', line 9 def request_count @request_count end |
#request_tm ⇒ Object (readonly)
Returns the value of attribute request_tm.
9 10 11 |
# File 'lib/sinew/main.rb', line 9 def request_tm @request_tm end |
#runtime_options ⇒ Object (readonly)
Returns the value of attribute runtime_options.
9 10 11 |
# File 'lib/sinew/main.rb', line 9 def @runtime_options end |
Instance Method Details
#cache ⇒ Object
http requests and caching
43 44 45 |
# File 'lib/sinew/main.rb', line 43 def cache @cache ||= Cache.new(self) end |
#http(method, url, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sinew/main.rb', line 47 def http(method, url, = {}) request = Request.new(self, method, url, ) # try to get from cache response = cache.get(request) # perform if necessary if !response response = perform(request) cache.set(response) end # always log error messages if response.error? puts "xxx http request failed with #{response.code}" end response end |
#output ⇒ Object
output
92 93 94 |
# File 'lib/sinew/main.rb', line 92 def output @output ||= Output.new(self) end |
#quiet? ⇒ Boolean
31 32 33 |
# File 'lib/sinew/main.rb', line 31 def quiet? [:quiet] end |
#run ⇒ Object
26 27 28 29 |
# File 'lib/sinew/main.rb', line 26 def run dsl.run if !quiet? end |