Sha256: 5396ab13c0d30989d8f46c7e2fc369cbe7dd20317c6b1ab83a302f76361ac7f7

Contents?: true

Size: 639 Bytes

Versions: 72

Compression:

Stored size: 639 Bytes

Contents

class Agilibox::TokenGenerator
  attr_reader :options

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

  def size
    options[:size] || self.class.default_size
  end

  def alphabet
    options[:alphabet] || self.class.default_alphabet
  end

  def call
    (alphabet * size).sample(size).join
  end

  class << self
    def call(*args)
      new(*args).call
    end

    attr_writer :default_size

    def default_size
      @default_size ||= 64
    end

    attr_writer :default_alphabet

    def default_alphabet
      @default_alphabet ||= (0..9).to_a + ("a".."z").to_a + ("A".."Z").to_a
    end
  end # class << self
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
agilibox-2.0.0 app/libs/agilibox/token_generator.rb
agilibox-1.11.0 app/libs/agilibox/token_generator.rb
agilibox-1.10.5 app/libs/agilibox/token_generator.rb
agilibox-1.10.2 app/libs/agilibox/token_generator.rb
agilibox-1.10.1 app/libs/agilibox/token_generator.rb
agilibox-1.10.0 app/libs/agilibox/token_generator.rb
agilibox-1.9.20 app/libs/agilibox/token_generator.rb
agilibox-1.9.19 app/libs/agilibox/token_generator.rb
agilibox-1.9.18 app/libs/agilibox/token_generator.rb
agilibox-1.9.17 app/libs/agilibox/token_generator.rb
agilibox-1.9.16 app/libs/agilibox/token_generator.rb
agilibox-1.9.15 app/libs/agilibox/token_generator.rb
agilibox-1.9.14 app/libs/agilibox/token_generator.rb
agilibox-1.9.13 app/libs/agilibox/token_generator.rb
agilibox-1.9.12 app/libs/agilibox/token_generator.rb
agilibox-1.9.11 app/libs/agilibox/token_generator.rb
agilibox-1.9.10 app/libs/agilibox/token_generator.rb
agilibox-1.9.9 app/libs/agilibox/token_generator.rb
agilibox-1.9.8 app/libs/agilibox/token_generator.rb
agilibox-1.9.7 app/libs/agilibox/token_generator.rb