<commit_before># CodeGenerator

Easily create unique and random tokens for your use.

## Installation

Add this line to your application's Gemfile:

    gem 'code_generator'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install code_generator

## Usage

Really simple:

    # creating random token
    token = CodeGenerator::Generate.generate
    
    # specific length
    token = CodeGenerator::Generate.generate(length: 10)

    # unique for particular field in a model
    token = CodeGenerator::Generate.generate(uniqueness: { model: :user, field: :confirmation_code })

## Configuration

You can configure the tokens to be generated. Simply create a new *'code_generator.rb'* file in the *'/config/initializers'* folder of your rails project:

    CodeGenerator.configure do |code|
      code.length         = 6               # length of the tokens to be generated.
      code.use_chars      = :numeric        # type of token to be generated. (default: :alpha_numeric)
      code.invalid_chars  = [ 0, 1, 7 ]     # do not use these characters.
      code.valid_chars    = [ 3, 4, 5, 6 ]  # use only these characters (ignores :use_chars).
      code.include_chars  = [ "$", "%" ]    # use these characters as well (does not ignore :use_chars).
      code.repeat_chars   = false           # each character to be used once. (default: true)
    end

You can use *:alpha, :lower_alpha, :upper_alpha, :numeric, :lower_alpha_numeric, :upper_alpha_numeric, :alpha_numeric* as various token types. Default is *:alpha_numeric*.

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

## Contributors

* [<NAME>](https://github.com/jitendra)
* [<NAME>](https://github.com/Bharat311)

## License

MIT License<commit_msg>Updated Readme for the tokenify! method<commit_after># CodeGenerator

Easily create unique and random tokens for your use.

## Installation

Add this line to your application's Gemfile:

    gem 'code_generator'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install code_generator

## Usage

Really simple:

    # creating random token
    token = CodeGenerator::Generate.generate
    
    # specific length
    token = CodeGenerator::Generate.generate(length: 10)

    # unique for particular field in a model
    token = CodeGenerator::Generate.generate(uniqueness: { model: :user, field: :confirmation_code })

## ORM - ActiveRecord/Mongoid

When using ActiveRecord or Mongoid as your rails project ORM, it also provides you the class method tokenify! that can be used to generate random, unique tokens for the specified field.

    # ActiveRecord
    class Service
      attr_accessible :auth_token
      
      tokenify!(:auth_token, length: 16)
    end

    # Mongoid
    class Service
      include Mongoid::CodeGenerator
      field :auth_token, type: String
      
      tokenify!(:auth_token, unique: true)
    end
    
In addition, you can pass the *:length (default: 10)* and *:unique (default: false)* options also.

## Configuration

You can configure the tokens to be generated. Simply create a new *'code_generator.rb'* file in the *'/config/initializers'* folder of your rails project:

    CodeGenerator.configure do |code|
      code.length         = 6               # length of the tokens to be generated. (default: 10)
      code.use_chars      = :numeric        # type of token to be generated. (default: :alpha_numeric)
      code.invalid_chars  = [ 0, 1, 7 ]     # do not use these characters. (default: none)
      code.valid_chars    = [ 3, 4, 5, 6 ]  # use only these characters (ignores :use_chars). (default: none)
      code.include_chars  = [ "$", "%" ]    # use these characters as well (does not ignore :use_chars). (default: none)
      code.repeat_chars   = false           # each character to be used once. (default: true)
    end

You can use *:alpha (a-Z), :lower_alpha (a-z), :upper_alpha (A-Z), :numeric (0-9), :lower_alpha_numeric (a-z, 0-9), :upper_alpha_numeric (A-Z, 0-9), :alpha_numeric (a-Z, 0-9)* as various token types. Default is *:alpha_numeric*.

**Note** - These configuration settings apply to the 'tokenify!' method as well.

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

## Contributors

* [<NAME>](https://github.com/jitendra)
* [<NAME>](https://github.com/Bharat311)

## License

MIT License
{'fraction_non_alphanumeric': 0.10253677254316777, 'fraction_numerical': 0.010658708164570454, 'mean_word_length': 3.25, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2575620', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1355, 'n_words': 513}