Class: Saper::Runtime
- Inherits:
-
Object
- Object
- Saper::Runtime
- Defined in:
- lib/saper/core/runtime.rb
Overview
Runtime provides a set of auxiliary functions to Saper actions: browser requests, keychain access, storage of variables.
Instance Attribute Summary collapse
-
#browser ⇒ Saper::Browser
readonly
Returns Saper::Browser instance used by runtime.
-
#keychain ⇒ Saper::Keychain
readonly
Returns Saper::Keychain instance used by runtime.
- #logger ⇒ Object readonly
-
#variables ⇒ Hash
readonly
Returns a Hash of variables stored by runtime.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Get variable value.
-
#[]=(name, value) ⇒ Object
Set variable value.
-
#bytes_received ⇒ Integer
Returns volume of incoming traffic (in bytes).
-
#bytes_sent ⇒ Integer
Returns volume of outgoing traffic (in bytes).
-
#copy ⇒ Saper::Runtime
Returns a duplicate instance of self.
-
#copy_without_variables ⇒ Saper::Runtime
Returns a duplicate instance of self without the stored variables.
-
#credentials(service) ⇒ Object?
Returns access credentials for specified service.
-
#http_requests ⇒ Integer
Returns number of HTTP requests.
-
#initialize(variables = {}, options = {}) ⇒ Saper::Runtime
constructor
Returns a new Saper::Runtime instance.
Constructor Details
#initialize(variables = {}, options = {}) ⇒ Saper::Runtime
Returns a new Saper::Runtime instance.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/saper/core/runtime.rb', line 28 def initialize(variables = {}, = {}) unless .is_a?(Hash) = {} end if [:logger].is_a?(Logger) @logger = [:logger] else @logger = Logger.new end if [:browser].is_a?(Browser) @browser = [:browser] else @browser = Browser.new(:agent => [:agent], :logger => logger) end if [:keychain].is_a?(Keychain) @keychain = [:keychain] end if [:keychain].is_a?(String) @keychain = Keychain.load([:keychain], :logger => logger) end unless @keychain.is_a?(Keychain) @keychain = Keychain.new({}, :logger => logger) end @variables = variables if block_given? yield self end end |
Instance Attribute Details
#browser ⇒ Saper::Browser (readonly)
Returns Saper::Browser instance used by runtime.
8 9 10 |
# File 'lib/saper/core/runtime.rb', line 8 def browser @browser end |
#keychain ⇒ Saper::Keychain (readonly)
Returns Saper::Keychain instance used by runtime.
12 13 14 |
# File 'lib/saper/core/runtime.rb', line 12 def keychain @keychain end |
#logger ⇒ Object (readonly)
19 20 21 |
# File 'lib/saper/core/runtime.rb', line 19 def logger @logger end |
#variables ⇒ Hash (readonly)
Returns a Hash of variables stored by runtime.
16 17 18 |
# File 'lib/saper/core/runtime.rb', line 16 def variables @variables end |
Instance Method Details
#[](name) ⇒ Object
Get variable value
78 79 80 |
# File 'lib/saper/core/runtime.rb', line 78 def [](name) @variables[name] end |
#[]=(name, value) ⇒ Object
Set variable value
86 87 88 |
# File 'lib/saper/core/runtime.rb', line 86 def []=(name, value) @variables[name] = value end |
#bytes_received ⇒ Integer
Returns volume of incoming traffic (in bytes)
59 60 61 |
# File 'lib/saper/core/runtime.rb', line 59 def bytes_received browser.received end |
#bytes_sent ⇒ Integer
Returns volume of outgoing traffic (in bytes)
65 66 67 |
# File 'lib/saper/core/runtime.rb', line 65 def bytes_sent browser.sent end |
#copy ⇒ Saper::Runtime
Returns a duplicate instance of self.
99 100 101 |
# File 'lib/saper/core/runtime.rb', line 99 def copy Runtime.new(variables.dup, :browser => browser, :keychain => keychain) end |
#copy_without_variables ⇒ Saper::Runtime
Returns a duplicate instance of self without the stored variables.
105 106 107 |
# File 'lib/saper/core/runtime.rb', line 105 def copy_without_variables Runtime.new({}, :browser => browser, :keychain => keychain) end |
#credentials(service) ⇒ Object?
Returns access credentials for specified service
93 94 95 |
# File 'lib/saper/core/runtime.rb', line 93 def credentials(service) keychain[service] end |
#http_requests ⇒ Integer
Returns number of HTTP requests
71 72 73 |
# File 'lib/saper/core/runtime.rb', line 71 def http_requests browser.requests end |