Class: Autosign::Journal
- Inherits:
-
Object
- Object
- Autosign::Journal
- Defined in:
- lib/autosign/journal.rb
Overview
processes are complete.
Instance Attribute Summary collapse
-
#settings ⇒ Hash
Settings of the autosign journal instance, such as the location of the journal file.
Instance Method Summary collapse
-
#add(uuid, validto, data = {}) ⇒ Object
Add a new token to the journal.
-
#initialize(settings = {}) ⇒ Autosign::Journal
constructor
Instance of the Autosign::Journal class.
Constructor Details
#initialize(settings = {}) ⇒ Autosign::Journal
Returns instance of the Autosign::Journal class.
17 18 19 20 21 22 |
# File 'lib/autosign/journal.rb', line 17 def initialize(settings = {}) @log = Logging.logger[self.class] @log.debug "initializing #{self.class.name}" @settings = settings fail unless setup end |
Instance Attribute Details
#settings ⇒ Hash
Returns settings of the autosign journal instance, such as the location of the journal file.
13 14 15 |
# File 'lib/autosign/journal.rb', line 13 def settings @settings end |
Instance Method Details
#add(uuid, validto, data = {}) ⇒ Object
Add a new token to the journal. Only succeeds if the token is not in the journal already.
This will only succeed if the token has not previously been added This is the primary way this class is expected to be used
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/autosign/journal.rb', line 38 def add(uuid, validto, data = {}) @log.debug "attempting to add UUID: '#{uuid.to_s}' which is valid to '#{Time.at(validto.to_i)}' with data #{data.to_s}" return false unless validate_uuid(uuid) store = setup # wrap the change in a transaction because multiple autosign instances # may try to run simultaneously. This will block until another process # releases the transaction lock. result = store.transaction do # check whether the UUID is already in the store if store.root?(uuid) @log.warn "Token with UUID '#{uuid}' is already saved in the journal, will not add'" store.abort else # save the token identified by UUID store[uuid.to_s] = {:validto => validto.to_s, :data => data} end end # return true if the transaction went through return !!result end |