lib/sqlserver/sequence.rb in sqlserver-sequence-0.2.0 vs lib/sqlserver/sequence.rb in sqlserver-sequence-0.3.0
- old
+ new
@@ -1,35 +1,39 @@
require 'active_support/concern'
+require 'sqlserver/sequence/configuration'
+require 'sqlserver/sequence//strategies'
require 'sqlserver/sequence/version'
module Sqlserver
module Sequence
extend ActiveSupport::Concern
- class_methods do
+ module ClassMethods
def sequence(field, options = {})
unless defined?(sequences)
include Sqlserver::Sequence::InstanceMethods
-
+ include next_value_strategy
+
class_attribute :sequences
self.sequences = {}
before_create :set_sequences
end
default_options = { name: field.to_s, format: nil, prefix: nil }
self.sequences[field] = default_options.merge(options)
end
+
+ private
+
+ def next_value_strategy
+ Sqlserver::Sequence.configuration.next_value_strategy ||
+ Strategies::NextValueFor
+ end
end
module InstanceMethods
- def next_sequence_value(sequence_name)
- self.class.connection.select_value(
- "select next value for #{sequence_name}"
- )
- end
-
private
def set_sequences
sequences.each do |field, options|
name = options[:name]