Class: Mongoid::Ids::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/ids/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Options

Returns a new instance of Options.



4
5
6
# File 'lib/mongoid/ids/options.rb', line 4

def initialize(options = {})
  @options = merge_defaults validate_options(options)
end

Instance Method Details

#containsObject



16
17
18
# File 'lib/mongoid/ids/options.rb', line 16

def contains
  @options[:contains]
end

#field_nameObject



20
21
22
# File 'lib/mongoid/ids/options.rb', line 20

def field_name
  @options[:field_name]
end

#field_name=(param) ⇒ Object



24
25
26
27
# File 'lib/mongoid/ids/options.rb', line 24

def field_name=(param)
  return if param.nil? || param.empty?
  @options[:field_name] = param
end

#lengthObject



8
9
10
# File 'lib/mongoid/ids/options.rb', line 8

def length
  @options[:length]
end

#patternObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mongoid/ids/options.rb', line 33

def pattern
  @options[:pattern] ||= \
  case @options[:contains].to_sym
  when :alphanumeric
    "%s#{@options[:length]}"
  when :alpha
    "%w#{@options[:length]}"
  when :alpha_upper
    "%C#{@options[:length]}"
  when :alpha_lower
    "%c#{@options[:length]}"
  when :numeric
    "%d1,#{@options[:length]}"
  when :fixed_numeric
    "%d#{@options[:length]}"
  when :fixed_numeric_no_leading_zeros
    "%D#{@options[:length]}"
  end
end

#retry_countObject



12
13
14
# File 'lib/mongoid/ids/options.rb', line 12

def retry_count
  @options[:retry_count]
end

#skip_finders?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mongoid/ids/options.rb', line 29

def skip_finders?
  @options[:skip_finders]
end