Sha256: ac16b60a328572de3529355d8fbac4d3d735c781a3818bed58d4dd8568eafc06

Contents?: true

Size: 533 Bytes

Versions: 10

Compression:

Stored size: 533 Bytes

Contents

# frozen_string_literal: true

require 'securerandom'

module RakeSecrets
  module Types
    class CharacterSet
      def initialize(character_set, opts = {})
        @character_set = character_set
        @character_count = character_set.length
        @length = opts[:length] || 32
      end

      def generate
        (1..@length)
          .collect { @character_set[random_index] }
          .join
      end

      private

      def random_index
        SecureRandom.random_number(@character_count)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rake_secrets-0.3.0.pre.2 lib/rake_secrets/types/character_set.rb
rake_secrets-0.3.0.pre.1 lib/rake_secrets/types/character_set.rb
rake_secrets-0.2.0 lib/rake_secrets/types/character_set.rb
rake_secrets-0.1.0.pre.8 lib/rake_secrets/types/character_set.rb
rake_secrets-0.1.0.pre.7 lib/rake_secrets/types/character_set.rb
rake_secrets-0.1.0.pre.6 lib/rake_secrets/types/character_set.rb
rake_secrets-0.1.0.pre.5 lib/rake_secrets/types/character_set.rb
rake_secrets-0.1.0.pre.4 lib/rake_secrets/types/character_set.rb
rake_secrets-0.1.0.pre.3 lib/rake_secrets/types/character_set.rb
rake_secrets-0.1.0.pre.2 lib/rake_secrets/types/character_set.rb