<commit_before># FlagShihTzu

This plugin lets you use a single integer column in an ActiveRecord model 
to store a collection of boolean flags. Each flag can be used almost in 
the same way you would use any boolean attribute on an ActiveRecord object.

The main benefit: 
**No migrations needed for new boolean attributes, which means no downtime!**

This is very useful for large tables where adding new columns can take 
a long time or if you just want to avoid adding new columns for every
boolean attribute.

Using FlagShihTzu, you can add new boolean attributes whenever you want, 
without needing any migration. Just change the has_flags call to include 
the new boolean flag. 


## Prerequisites

FlagShihTzu assumes that your ActiveRecord model already has an integer field 
named flags, which should be defined to not allow NULL values and should have 
a default value of 0 (which means all flags are initially set to false).

The plugin has been tested with Rails versions from 2.1 to 2.3 and MySQL.


## Installation

    cd path/to/your/rails-project
    ./script/plugin install git://github.com/xing/flag_shih_tzu.git


## Usage

    class Spaceship < ActiveRecord::Base
      include FlagShihTzu

      has_flags 1 => :warpdrive,
                2 => :shields,
                3 => :electrolytes

    end

`has_flags` takes a hash. The keys must be positive integers and should not 
be changed once in use, as they represent the position of the bit being used 
to enable or disable a flag. The values are symbols for the flags
being created.

Calling `has_flags` as shown above creates the following instance methods 
on Spaceship:

    Spaceship#warpdrive
    Spaceship#warpdrive?
    Spaceship#warpdrive=
    Spaceship#shields
    Spaceship#shields?
    Spaceship#shields=
    Spaceship#electrolytes
    Spaceship#electrolytes?
    Spaceship#electrolytes=

The following named scopes are available, too:

    Spaceship.warpdrive         # :conditions => "(spaceships.flags & 1 = 1)"
    Spaceship.not_warpdrive     # :conditions => "(spaceships.flags & 1 = 0)"
    Spaceship.shields           # :conditions => "(spaceships.flags & 2 = 1)"
    Spaceship.not_shields       # :conditions => "(spaceships.flags & 2 = 0)"
    Spaceship.electrolytes      # :conditions => "(spaceships.flags & 4 = 1)"
    Spaceship.not_electrolytes  # :conditions => "(spaceships.flags & 4 = 0)"
    
If you do not want the named scopes to be defined, set the
`:named_scopes` option to false when calling has_flags:
    
    has_flags({ 1 => :warpdrive, 2 => :shields, 3 => :electrolytes }, :generate_named_scopes => false)

Additionally, the following class methods may support you when
manually building ActiveRecord conditions:

    Spaceship.warpdrive                   # "(spaceships.flags & 1 = 1)"
    Spaceship.not_warpdrive               # "(spaceships.flags & 1 = 0)"
    Spaceship.shields                     # "(spaceships.flags & 2 = 1)"
    Spaceship.not_shields                 # "(spaceships.flags & 2 = 0)"
    Spaceship.electrolytes_condition      # "(spaceships.flags & 4 = 1)"
    Spaceship.not_electrolytes_condition  # "(spaceships.flags & 4 = 0)"
  
### Example

    enterprise = Spaceship.new
    enterprise.warpdrive = true
    enterprise.shields = true
    enterprise.electrolytes = false
    enterprise.save
  
    if spaceship.shields?
      ...
    end

    Spaceship.warpdrive.find(:all)
    Spaceship.not_electrolytes.count
    ...


## Authors

[<NAME>](http://github.com/ppeszko), 
[<NAME>](http://github.com/boosty), 
[<NAME>](http://github.com/alpinegizmo) 
and [<NAME>](http://github.com/dizzy42)

## Contributors

[TobiTobes](http://github.com/rngtng)

Copyright (c) 2009 [XING AG](http://www.xing.com/)
Released under the MIT license

Please find out more about our work in our 
[tech blog](http://blog.xing.com/category/english/tech-blog).
<commit_msg>Fixed typo in README<commit_after># FlagShihTzu

This plugin lets you use a single integer column in an ActiveRecord model 
to store a collection of boolean flags. Each flag can be used almost in 
the same way you would use any boolean attribute on an ActiveRecord object.

The main benefit: 
**No migrations needed for new boolean attributes, which means no downtime!**

This is very useful for large tables where adding new columns can take 
a long time or if you just want to avoid adding new columns for every
boolean attribute.

Using FlagShihTzu, you can add new boolean attributes whenever you want, 
without needing any migration. Just change the has_flags call to include 
the new boolean flag. 


## Prerequisites

FlagShihTzu assumes that your ActiveRecord model already has an integer field 
named flags, which should be defined to not allow NULL values and should have 
a default value of 0 (which means all flags are initially set to false).

The plugin has been tested with Rails versions from 2.1 to 2.3 and MySQL.


## Installation

    cd path/to/your/rails-project
    ./script/plugin install git://github.com/xing/flag_shih_tzu.git


## Usage

    class Spaceship < ActiveRecord::Base
      include FlagShihTzu

      has_flags 1 => :warpdrive,
                2 => :shields,
                3 => :electrolytes

    end

`has_flags` takes a hash. The keys must be positive integers and should not 
be changed once in use, as they represent the position of the bit being used 
to enable or disable a flag. The values are symbols for the flags
being created.

Calling `has_flags` as shown above creates the following instance methods 
on Spaceship:

    Spaceship#warpdrive
    Spaceship#warpdrive?
    Spaceship#warpdrive=
    Spaceship#shields
    Spaceship#shields?
    Spaceship#shields=
    Spaceship#electrolytes
    Spaceship#electrolytes?
    Spaceship#electrolytes=

The following named scopes are available, too:

    Spaceship.warpdrive         # :conditions => "(spaceships.flags & 1 = 1)"
    Spaceship.not_warpdrive     # :conditions => "(spaceships.flags & 1 = 0)"
    Spaceship.shields           # :conditions => "(spaceships.flags & 2 = 1)"
    Spaceship.not_shields       # :conditions => "(spaceships.flags & 2 = 0)"
    Spaceship.electrolytes      # :conditions => "(spaceships.flags & 4 = 1)"
    Spaceship.not_electrolytes  # :conditions => "(spaceships.flags & 4 = 0)"
    
If you do not want the named scopes to be defined, set the
`:named_scopes` option to false when calling has_flags:
    
    has_flags({ 1 => :warpdrive, 2 => :shields, 3 => :electrolytes }, :named_scopes => false)

Additionally, the following class methods may support you when
manually building ActiveRecord conditions:

    Spaceship.warpdrive                   # "(spaceships.flags & 1 = 1)"
    Spaceship.not_warpdrive               # "(spaceships.flags & 1 = 0)"
    Spaceship.shields                     # "(spaceships.flags & 2 = 1)"
    Spaceship.not_shields                 # "(spaceships.flags & 2 = 0)"
    Spaceship.electrolytes_condition      # "(spaceships.flags & 4 = 1)"
    Spaceship.not_electrolytes_condition  # "(spaceships.flags & 4 = 0)"
  
### Example

    enterprise = Spaceship.new
    enterprise.warpdrive = true
    enterprise.shields = true
    enterprise.electrolytes = false
    enterprise.save
  
    if spaceship.shields?
      ...
    end

    Spaceship.warpdrive.find(:all)
    Spaceship.not_electrolytes.count
    ...


## Authors

[<NAME>](http://github.com/ppeszko), 
[<NAME>](http://github.com/boosty), 
[<NAME>](http://github.com/alpinegizmo) 
and [<NAME>](http://github.com/dizzy42)

## Contributors

[TobiTobes](http://github.com/rngtng)

Copyright (c) 2009 [XING AG](http://www.xing.com/)
Released under the MIT license

Please find out more about our work in our 
[tech blog](http://blog.xing.com/category/english/tech-blog).

{'fraction_non_alphanumeric': 0.08983268983268983, 'fraction_numerical': 0.010553410553410553, 'mean_word_length': 3.191477885652643, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '864203', 'n_tokens_mistral': 2512, 'n_tokens_neox': 2315, 'n_words': 797}