<commit_before># Virtus::ROM

This gem will allow you to use Virtus to define ROM (Ruby Object Mapper) model attributes.
It will also automatically map the model objects for you.


## Installation

Add this line to your application's Gemfile:

    gem 'virtus-rom'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install virtus-rom

## Usage

TODO: Write usage instructions here

## 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<commit_msg>Update README with and usage details.<commit_after># Virtus::ROM

This gem will allow you to use Virtus to define ROM (Ruby Object Mapper) model attributes.
It will also automatically map the model objects for you.


## Installation

Add this line to your application's Gemfile:

    gem 'virtus-rom'

And then execute:

    $ bundle


## Usage

To use Virtus::ROM, you'll need to first define the ROM repository.
We'd recommend that you do this in your configuration setup (i.e. a Rails initializer):

```ruby
env = ROM::Environment.setup(default: 'memory://test')
```

Then simply add `include Virtus::ROM.model` to your model class, and define the model attributes using Virtus.
For example:

```ruby
class User
  include Virtus::ROM.model

  attribute :name, String, from: :first_name
  attribute :age, Integer, required: false
end
```

Virtus::ROM will use the `default` repository by default, but you can override with a `repository` directive:

```ruby
env = ROM::Environment.setup(pg: 'postgres://localhost/pg')

class User
  include Virtus::ROM.model

  repository :pg

  attribute :name, String, from: :first_name
  attribute :age, Integer, required: false
end
```

By default, Virtus::ROM will use a table within the repository with the pluralized/underscored name of the class.
This can be overridden with a `table` directive:

```ruby
class User
  include Virtus::ROM.model

  table :all_users # Should probably use a less DB-oriented term - relation?

  attribute :name, String, from: :first_name
  attribute :age, Integer, required: false
end
```

Once you've defined your model, a ROM mapping will be created for you, and you can then use ROM as you normally would:

```ruby
env = ROM::Environment.setup(default: 'memory://test')

class User
  include Virtus::ROM.model

  attribute :name, String, from: :first_name
  attribute :age, Integer, required: false
end

env[:users].save(User.new(name: 'Craig'))
craig = env[:users].restrict(name: 'Craig').one
```


## 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
{'fraction_non_alphanumeric': 0.09909281228192603, 'fraction_numerical': 0.0034891835310537334, 'mean_word_length': 4.270220588235294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6449606', 'n_tokens_mistral': 902, 'n_tokens_neox': 824, 'n_words': 375}