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 |
# File 'lib/sinew/main.rb', line 11 def initialize() super() # init @runtime_options = RuntimeOptions.new @request_tm = Time.at(0) @request_count = 0 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
37 38 39 |
# File 'lib/sinew/main.rb', line 37 def cache @cache ||= Cache.new(self) end |
#http(method, url, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sinew/main.rb', line 41 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
86 87 88 |
# File 'lib/sinew/main.rb', line 86 def output @output ||= Output.new(self) end |
#quiet? ⇒ Boolean
25 26 27 |
# File 'lib/sinew/main.rb', line 25 def quiet? [:quiet] end |
#run ⇒ Object
20 21 22 23 |
# File 'lib/sinew/main.rb', line 20 def run dsl.run if !quiet? end |