Module: UniqIdentifier

Extended by:
Configure
Defined in:
lib/uniq_identifier.rb,
lib/uniq_identifier/hook.rb,
lib/uniq_identifier/railtie.rb,
lib/uniq_identifier/version.rb,
lib/uniq_identifier/configure.rb,
lib/uniq_identifier/configuration.rb,
lib/generators/uniq_identifier/add_generator.rb,
lib/generators/uniq_identifier/install_generator.rb

Defined Under Namespace

Modules: Configure, Generators, Hook Classes: Configuration, Railtie

Constant Summary collapse

MAJOR =
0
MINOR =
1
PATCH =
1
VERSION =
[MAJOR, MINOR, PATCH].join('.')

Instance Attribute Summary

Attributes included from Configure

#configuration

Instance Method Summary collapse

Methods included from Configure

configure

Instance Method Details

#uniq_identifier(auto: true, validate: true, generator: :default) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/uniq_identifier.rb', line 8

def uniq_identifier(auto: true, validate: true, generator: :default)
  @uniq_identifier_generator = generator

  class << self
    def uniq_identifier_generator
      generator = @uniq_identifier_generator
      if generator.nil? && superclass.respond_to?(:uniq_identifier_generator)
        superclass.uniq_identifier_generator
      elsif generator == :default
        UniqIdentifier.configuration.generator
      else
        generator
      end
    end
  end

  if auto
    before_validation :set_uniq_identifier
    include Hook
  end

  if validate
    validates :uuid, presence: true, uniqueness: true
  end
end