class Mongoid::Token::Options
Public Class Methods
new(options = {})
click to toggle source
# File lib/mongoid/token/options.rb, line 2 def initialize(options = {}) @options = merge_defaults validate_options(options) end
Public Instance Methods
contains()
click to toggle source
# File lib/mongoid/token/options.rb, line 14 def contains @options[:contains] end
field_name()
click to toggle source
# File lib/mongoid/token/options.rb, line 18 def field_name !@options[:id] && @options[:field_name] || :_id end
generate_on_init()
click to toggle source
# File lib/mongoid/token/options.rb, line 30 def generate_on_init @options[:id] || @options[:generate_on_init] end
length()
click to toggle source
# File lib/mongoid/token/options.rb, line 6 def length @options[:length] end
override_to_param?()
click to toggle source
# File lib/mongoid/token/options.rb, line 26 def override_to_param? @options[:override_to_param] end
pattern()
click to toggle source
# File lib/mongoid/token/options.rb, line 34 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]}" when :fixed_hex_numeric "%h#{@options[:length]}" when :fixed_hex_numeric_no_leading_zeros "%H#{@options[:length]}" end end
retry_count()
click to toggle source
# File lib/mongoid/token/options.rb, line 10 def retry_count @options[:retry_count] end
skip_finders?()
click to toggle source
# File lib/mongoid/token/options.rb, line 22 def skip_finders? @options[:skip_finders] end
Private Instance Methods
merge_defaults(options)
click to toggle source
# File lib/mongoid/token/options.rb, line 66 def merge_defaults(options) { id: false, length: 4, retry_count: 3, contains: :alphanumeric, field_name: :token, skip_finders: false, override_to_param: true, generate_on_init: false }.merge(options) end
validate_options(options)
click to toggle source
# File lib/mongoid/token/options.rb, line 58 def validate_options(options) if options.has_key?(:retry) STDERR.puts "Mongoid::Token Deprecation Warning: option `retry` has been renamed to `retry_count`. `:retry` will be removed in v2.1" options[:retry_count] = options[:retry] end options end