0.01
No commit activity in last 3 years
No release in over 3 years
Ever wanted to have active-record like relations in your POROs?, here is a proposed solution.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

active_poro

Gem Version Test Coverage

Makes possible the use of has_many, has_one, belongs_to associations in POROs as you would expect

Installation

Add this line to your application's Gemfile:

gem 'active_poro'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_poro

Usage

You may use ActivePoro::Model as a mixin to enable associations to be built between POROs Currently supported associations:

  • has_many
  • has_one
  • belongs_to

Example:

require 'active_poro'

class Dog
  include ActivePoro::Model
  has_many :fleas
end

class Flea
  include ActivePoro::Model
  belongs_to :dog
end

Now, with that in place you should be able to do

dog = Dog.new
flea_a = Flea.new
flea_b = Flea.new

# associate the fleas with the dog
dog.fleas = [flea_a, flea_b]

# now fleas have the dog associated back
flea_a.dog == dog
#=> true

# now fleas have the dog associated back
flea_b.dog == dog
#=> true

# if a new dog is created
another_dog = Dog.new

# and flea_b for example, jumps to it (i.e. is associated to this other dog)
flea_b.dog = another_dog

# then dog does not have flea_b now
dog.fleas
#=> [flea_a] # simplified output, not actual output on the console

# and another_dog gets flea_b
another_dog.fleas

#=> [flea_b] # simplified output, not actual output on the console

This also works with has_one and belongs_to as expected.

Contributing

  1. Fork it ( https://github.com/codescrum/active_poro/fork )
  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 a new Pull Request