Class: Aspera::PersistencyActionOnce
- Inherits:
-
Object
- Object
- Aspera::PersistencyActionOnce
- Defined in:
- lib/aspera/persistency_action_once.rb
Overview
Persist data on file system
Instance Method Summary collapse
-
#initialize(options) ⇒ PersistencyActionOnce
constructor
A new instance of PersistencyActionOnce.
- #save ⇒ Object
Constructor Details
#initialize(options) ⇒ PersistencyActionOnce
Returns a new instance of PersistencyActionOnce.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/aspera/persistency_action_once.rb', line 14 def initialize() Log.log.debug("persistency: #{options}") raise "options shall be Hash" unless .is_a?(Hash) raise "mandatory :manager" if [:manager].nil? raise "mandatory :data" if [:data].nil? raise "mandatory :ids (Array)" unless [:ids].is_a?(Array) raise "mandatory 1 element in :ids" unless [:ids].length >= 1 @manager=[:manager] @persisted_object=[:data] @object_ids=[:ids] # by default , at save time, file is deleted if data is nil @delete_condition=[:delete] || lambda{|d|d.empty?} @persist_format=[:format] || lambda {|h| JSON.generate(h)} persist_parse=[:parse] || lambda {|t| JSON.parse(t)} persist_merge=[:merge] || lambda {|current,file| current.concat(file).uniq rescue current} value=@manager.get(@object_ids) persist_merge.call(@persisted_object,persist_parse.call(value)) unless value.nil? end |
Instance Method Details
#save ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/aspera/persistency_action_once.rb', line 33 def save if @delete_condition.call(@persisted_object) @manager.delete(@object_ids) else @manager.put(@object_ids,@persist_format.call(@persisted_object)) end end |