<commit_before># HierarchicalDb

This gem has the implementation of **[Hierarchical databases](http://www.sitepoint.com/hierarchical-data-database/)**

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'hierarchical_db'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install hierarchical_db

Next you have to use the hierarchical_db generator into your model. For example, if you have a model called *Territory* (to manage countries, cities and all the other hierarchies) with the following relationship:
```ruby
class Territory < ActiveRecord::Base
  belongs_to :parent_territory, class_name: 'Territory'
end
```
You have to execute the generator with the code below:
```
rails g hierarchical_db territories
```
Now your model has the attributes *lft* and *rgt*.

Next into the model you have to include Hierarchies adding the code below:
```ruby
class Territory < ActiveRecord::Base
  include HierarchicalDb #we added this
  belongs_to :parent_territory, class_name: 'Territory'
end
```
Finally we add two alias methods that are useful and necessary to deal with hierarchies:
```ruby
class Territory < ActiveRecord::Base
  include HierarchicalDb 
  belongs_to :parent_territory, class_name: 'Territory'
  # alias methods
  alias_method :children, :territories #we added this
  alias_method :parent, :parent_territory #we added this
end
```
## Usage

Continuing the example, if you have data inside your Territory model, then you have to execute :
```ruby
  Territory.sort_tree
```
This command initializes your tree and fills *lft* and *rgt* attributes with corresponding information.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hierarchical_db. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.


## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

<commit_msg>better explanation<commit_after># HierarchicalDb

This gem has the implementation of **[Hierarchical databases](http://www.sitepoint.com/hierarchical-data-database/)**

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'hierarchical_db'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install hierarchical_db

Next you have to use the hierarchical_db generator into your model. For example, if you have a model called *Territory* (to manage countries, cities and all the other hierarchies) with the following relationship:
```ruby
class Territory < ActiveRecord::Base
  belongs_to :parent_territory, class_name: 'Territory'
end
```
You have to execute the generator with the code below:
```
rails g hierarchical_db territories
```
Now your model has the attributes *lft* and *rgt* that are essential to the gem work properly.

Next into the model you have to include Hierarchies adding the code below:
```ruby
class Territory < ActiveRecord::Base
  include HierarchicalDb #we added this
  belongs_to :parent_territory, class_name: 'Territory'
end
```
Finally we add two alias methods that are useful and necessary to deal with hierarchies:
```ruby
class Territory < ActiveRecord::Base
  include HierarchicalDb 
  belongs_to :parent_territory, class_name: 'Territory'
  # alias methods
  alias_method :children, :territories #we added this
  alias_method :parent, :parent_territory #we added this
end
```
## Usage

Continuing the example, if you have data inside your Territory model, then you have to execute :
```ruby
  Territory.sort_tree
```
This command initializes your tree and fills *lft* and *rgt* attributes with corresponding information.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hierarchical_db. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.


## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).


{'fraction_non_alphanumeric': 0.07644511391451704, 'fraction_numerical': 0.0, 'mean_word_length': 4.941834451901566, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1580806', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1403, 'n_words': 681}