Module: ScopedId::Concern

Extended by:
ActiveSupport::Concern
Defined in:
lib/scoped_id/concern.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#generate_next_scoped_idsObject



34
35
36
37
38
39
40
41
# File 'lib/scoped_id/concern.rb', line 34

def generate_next_scoped_ids
  self.class.scoped_ids_definitions.each do |definition|
    attr_name = definition.attr_name
    if send("#{attr_name}").nil?
      send "#{attr_name}=", send("get_next_scoped_id", definition)
    end
  end
end

#get_next_scoped_id(scoped_id_definition) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/scoped_id/concern.rb', line 43

def get_next_scoped_id(scoped_id_definition)
  attr_name  = scoped_id_definition.attr_name
  scope_attr = scoped_id_definition.scope_attr

  scope = self.class.where(scope_attr => read_attribute(scope_attr))
  current_max_scoped_id = scope.maximum(attr_name) || 0
  current_max_scoped_id + 1
end