Class: Contr::Sampler::Default
- Defined in:
- lib/contr/sampler/default.rb
Constant Summary collapse
- DEFAULT_FOLDER =
"/tmp/contracts"
- DEFAULT_PATH_TEMPLATE =
"%<contract_name>s/%<period_id>i.dump"
- DEFAULT_PERIOD =
10 minutes
10 * 60
Instance Attribute Summary collapse
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#path_template ⇒ Object
readonly
Returns the value of attribute path_template.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Instance Method Summary collapse
-
#initialize(folder: DEFAULT_FOLDER, path_template: DEFAULT_PATH_TEMPLATE, period: DEFAULT_PERIOD) ⇒ Default
constructor
A new instance of Default.
- #read(path: nil, contract_name: nil, period_id: nil) ⇒ Object
- #sample!(state) ⇒ Object
Constructor Details
#initialize(folder: DEFAULT_FOLDER, path_template: DEFAULT_PATH_TEMPLATE, period: DEFAULT_PERIOD) ⇒ Default
Returns a new instance of Default.
14 15 16 17 18 |
# File 'lib/contr/sampler/default.rb', line 14 def initialize(folder: DEFAULT_FOLDER, path_template: DEFAULT_PATH_TEMPLATE, period: DEFAULT_PERIOD) @folder = folder @path_template = path_template @period = period end |
Instance Attribute Details
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
12 13 14 |
# File 'lib/contr/sampler/default.rb', line 12 def folder @folder end |
#path_template ⇒ Object (readonly)
Returns the value of attribute path_template.
12 13 14 |
# File 'lib/contr/sampler/default.rb', line 12 def path_template @path_template end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
12 13 14 |
# File 'lib/contr/sampler/default.rb', line 12 def period @period end |
Instance Method Details
#read(path: nil, contract_name: nil, period_id: nil) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/contr/sampler/default.rb', line 30 def read(path: nil, contract_name: nil, period_id: nil) path ||= dump_path(contract_name, period_id) dump = File.read(path) Marshal.load(dump) end |
#sample!(state) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/contr/sampler/default.rb', line 20 def sample!(state) path = dump_path(state[:contract_name]) return if dump_present?(path) dump = Marshal.dump(state) save_dump(dump, path) create_dump_info(path) end |