Class: Steenzout::SequenceManager
- Inherits:
-
Object
- Object
- Steenzout::SequenceManager
- Defined in:
- lib/sqnc/manager.rb,
lib/sqnc/file/manager.rb,
lib/sqnc/manager_file.rb,
lib/sqnc/kyotocabinet/manager.rb,
lib/sqnc/tokyocabinet/manager.rb
Constant Summary collapse
- @@sequences =
{}
Class Attribute Summary collapse
-
.implementations ⇒ Object
Returns the list of allowed sequence management implementations.
-
.sequences ⇒ Object
Returns a list of the current sequence names being managed.
Class Method Summary collapse
-
.current_value(name) ⇒ Object
Returns the current in-memory value for this sequence.
-
.increment(name) ⇒ Object
Increments and returns the given sequence by step (or offset + step if it has never been used before).
- .increment_sequence(name) ⇒ Object
- .list_sequences ⇒ Object
-
.load ⇒ Object
Validates the configuration and loads the class with the given implementation.
- .load_from_tokyocabinet ⇒ Object
- .load_from_yaml ⇒ Object
- .reload ⇒ Object
Class Attribute Details
.implementations ⇒ Object
Returns the list of allowed sequence management implementations.
74 75 76 |
# File 'lib/sqnc/manager.rb', line 74 def implementations @implementations end |
.sequences ⇒ Object
Returns a list of the current sequence names being managed.
128 129 130 |
# File 'lib/sqnc/manager.rb', line 128 def sequences @sequences end |
Class Method Details
.current_value(name) ⇒ Object
Returns the current in-memory value for this sequence. WARNING: if the sequence hasn’t been used yet, a nil value will be returned.
62 63 64 65 66 67 68 |
# File 'lib/sqnc/manager.rb', line 62 def self.current_value(name) raise ArgumentError.new "The sequence #{name} doesn't exist!" if !@sequences.has_key? name return @sequences[name] end |
.increment(name) ⇒ Object
Increments and returns the given sequence by step (or offset + step if it has never been used before).
84 85 86 87 |
# File 'lib/sqnc/manager.rb', line 84 def self.increment(name) raise ArgumentError.new "The sequence #{name} doesn't exist!" if !@sequences.has_key? name self.increment_and_store name end |
.increment_sequence(name) ⇒ Object
26 27 28 |
# File 'lib/sqnc/manager_file.rb', line 26 def self.increment_sequence name @@sequences[name] = @@sequences[name] + 1 end |
.list_sequences ⇒ Object
22 23 24 |
# File 'lib/sqnc/manager_file.rb', line 22 def self.list_sequences @@sequences end |
.load ⇒ Object
Validates the configuration and loads the class with the given implementation.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/sqnc/manager.rb', line 93 def self.load # retrieve configuration @config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-sqnc' @config[:sequences] ||= {} # validation if !@config.has_key? :implementation or @config[:implementation].nil? = "implementation property is missing from the configuration file!" raise ArgumentError.new end raise ArgumentError.new "there is no #{@config[:implementation]} implementation!" if !@implementations.include? @config[:implementation] or !File.exist? "#{File.dirname(__FILE__)}/#{@config[:implementation]}/manager.rb" # load implementation require "#{File.dirname(__FILE__)}/#{@config[:implementation]}/manager" # load sequences load_sequences end |
.load_from_tokyocabinet ⇒ Object
7 8 9 |
# File 'lib/sqnc/manager_file.rb', line 7 def self.load_from_tokyocabinet end |
.load_from_yaml ⇒ Object
11 12 13 14 |
# File 'lib/sqnc/manager_file.rb', line 11 def self.load_from_yaml config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-sqnc' @@sequences = config[:sequences] end |
.reload ⇒ Object
16 17 18 19 |
# File 'lib/sqnc/manager_file.rb', line 16 def self.reload config = Steenzout::ConfigurationManager.configuration_for_gem 'steenzout-sqnc' load_from_yaml if config[:method] == 'yaml' end |