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-1.9.6 app/libs/agilibox/token_generator.rb
agilibox-1.9.5 app/libs/agilibox/token_generator.rb
agilibox-1.9.4 app/libs/agilibox/token_generator.rb
agilibox-1.9.3 app/libs/agilibox/token_generator.rb
agilibox-1.9.1 app/libs/agilibox/token_generator.rb
agilibox-1.9.0 app/libs/agilibox/token_generator.rb
agilibox-1.8.0 app/libs/agilibox/token_generator.rb
agilibox-1.7.4 app/libs/agilibox/token_generator.rb
agilibox-1.7.3 app/libs/agilibox/token_generator.rb
agilibox-1.7.2 app/libs/agilibox/token_generator.rb
agilibox-1.7.1 app/libs/agilibox/token_generator.rb
agilibox-1.7.0 app/libs/agilibox/token_generator.rb
agilibox-1.6.2 app/libs/agilibox/token_generator.rb
agilibox-1.6.1 app/libs/agilibox/token_generator.rb
agilibox-1.6.0 app/libs/agilibox/token_generator.rb
agilibox-1.5.13 app/libs/agilibox/token_generator.rb
agilibox-1.5.12 app/libs/agilibox/token_generator.rb
agilibox-1.5.11 app/libs/agilibox/token_generator.rb
agilibox-1.5.10 app/libs/agilibox/token_generator.rb
agilibox-1.5.9 app/libs/agilibox/token_generator.rb