Class: Steenzout::SequenceManager

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Class Attribute Details

.implementationsObject

Returns the list of allowed sequence management implementations.



74
75
76
# File 'lib/sqnc/manager.rb', line 74

def implementations
  @implementations
end

.sequencesObject

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.

Parameters:

  • name:

    the sequence name.



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).

Parameters:

  • name:

    the sequence name.



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_sequencesObject



22
23
24
# File 'lib/sqnc/manager_file.rb', line 22

def self.list_sequences
  @@sequences
end

.loadObject

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?
    error_message = "implementation property is missing from the configuration file!"
    raise ArgumentError.new error_message
  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_tokyocabinetObject



7
8
9
# File 'lib/sqnc/manager_file.rb', line 7

def self.load_from_tokyocabinet

end

.load_from_yamlObject



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

.reloadObject



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