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.3.0 app/libs/agilibox/token_generator.rb
agilibox-1.2.3 app/libs/agilibox/token_generator.rb
agilibox-1.2.2 app/libs/agilibox/token_generator.rb
agilibox-1.2.1 app/libs/agilibox/token_generator.rb
agilibox-1.2.0 app/libs/agilibox/token_generator.rb
agilibox-1.1.0 app/libs/agilibox/token_generator.rb
agilibox-1.0.15 app/libs/agilibox/token_generator.rb
agilibox-1.0.14 app/libs/agilibox/token_generator.rb
agilibox-1.0.13 app/libs/agilibox/token_generator.rb
agilibox-1.0.12 app/libs/agilibox/token_generator.rb
agilibox-1.0.11 app/libs/agilibox/token_generator.rb
agilibox-1.0.10 app/libs/agilibox/token_generator.rb