consort 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +1 -1
- data/CHANGELOG.md +4 -1
- data/LICENSE +2 -2
- data/README.md +18 -7
- data/consort.gemspec +1 -1
- data/lib/consort/active_record.rb +7 -1
- data/lib/consort/mongoid.rb +8 -2
- data/lib/consort/version.rb +1 -1
- data/test/db/schema.rb +4 -4
- data/test/models.rb +9 -9
- data/test/test_active_record.rb +11 -5
- data/test/test_helper.rb +8 -9
- data/test/test_mongoid.rb +5 -1
- metadata +2 -3
- data/LICENSE.txt +0 -22
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Nzk4NGRkZDVhOTRjNjA5Nzk3NGJhODhiYTI1NGIzOGNiZWY1MzUwOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWY0NDFkNjIwY2VhNTI4MzIwMzM4YzU2MWNmNGE2MDI0ZDM0MjE5MQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjE4OGViYzAwZTRiYjE4MzQxOWZhMDVjYTcyMjhhNjcwYWUxZDk0ZGU4OTVl
|
10
|
+
YzRlZDBmNDQzZTU2NjUyNzg1MWZiZjU0MzQ1ZmQzNDFjM2RlNWJjYjY0NzEz
|
11
|
+
ZmIzMDc0ZmI5ZDI4ZjI5ZWRiZjY4ODA0OWMyZDg2OTExZTBlMzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTdjNGRkYTYyZjdjNjIwZGY5OWVkZjczY2I4ZGVkMDdiNGQ5NjhkODQ5ZTE0
|
14
|
+
M2ZjMWEyMDg3N2NjZjI5YjM5Y2RiOTYzMjRhMzllNjhkNmUxODMxNjk0OTQ1
|
15
|
+
M2QwNWUwZDk1NWZkNmJjYzk1ZGMwMGI3OTI2MTkzZmY2NDk5ZjI=
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
1
|
Copyright (c) 2013 Colin Mattson
|
4
2
|
|
3
|
+
The MIT License (MIT)
|
4
|
+
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
7
7
|
the Software without restriction, including without limitation the rights to
|
data/README.md
CHANGED
@@ -3,11 +3,18 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/cmattson/consort.png?branch=master)](https://travis-ci.org/cmattson/consort)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/cmattson/consort/badge.png)](https://coveralls.io/r/cmattson/consort)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/cmattson/consort.png)](https://codeclimate.com/github/cmattson/consort)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/consort.png)](http://badge.fury.io/rb/consort)
|
6
7
|
|
7
8
|
Mixing ActiveRecord and other ORMs like Mongoid? Need relationships between those data layers? Really hate either implementing a bunch of accessors or copy-pasting the same metaprogramming over and over again?
|
8
9
|
|
9
10
|
Use Consort! Built around a simple modification to standard ActiveRecord association syntax, Consort allows you to more easily retrieve data from cross-ORM single-to-single and single-to-many associations without writing or recycling code.
|
10
11
|
|
12
|
+
##### Once More, With 50% Less Jargon
|
13
|
+
|
14
|
+
If you have a Rails app using both ActiveRecord and Mongoid, you've probably discovered you can't create associations between the two.
|
15
|
+
|
16
|
+
Consort allows you to define has_one, has_many, and belongs_to associations between ActiveRecord and Mongoid object classes. (And it can be extended to support nearly any combination of ORM adapters, but ActiveRecord <-> Mongoid is what's written today.)
|
17
|
+
|
11
18
|
## Installation
|
12
19
|
|
13
20
|
Add this line to your application's Gemfile:
|
@@ -30,7 +37,7 @@ Ruby 1.8 is not supported.
|
|
30
37
|
|
31
38
|
### Rails Compatibility
|
32
39
|
|
33
|
-
|
40
|
+
Consort currently targets Rails 3.2. Mongoid and several other ORM layers have not yet been updated for Rails 4, and most projects are continuing to use Rails 3.2 for now. Consort has not been tested against earlier Rails 3 versions; if you're stuck on an earlier version, let me know how it works for you.
|
34
41
|
|
35
42
|
Rails 4 support is planned.
|
36
43
|
|
@@ -38,12 +45,17 @@ Rails 4 support is planned.
|
|
38
45
|
|
39
46
|
Consort allows basic relationships to be defined between ActiveRecord and other ORM layers. Simply add `_[ORM_TYPE]` to what you'd normally use. `active_record` and `mongoid` are currently supported.
|
40
47
|
|
48
|
+
The relationship macros are designed to read cleanly:
|
49
|
+
|
50
|
+
* Airframe has one ActiveRecord powerplant
|
51
|
+
* Airframe has many Mongoid variants
|
52
|
+
|
41
53
|
On an ActiveRecord model, you can define relationships with Mongoid:
|
42
54
|
```ruby
|
43
55
|
class Airframe < ActiveRecord::Base
|
44
56
|
belongs_to_mongoid :manufacturer
|
45
|
-
has_one_mongoid
|
46
|
-
|
57
|
+
has_one_mongoid :powerplant
|
58
|
+
has_many_mongoid :variants
|
47
59
|
end
|
48
60
|
```
|
49
61
|
|
@@ -53,15 +65,15 @@ class Airframe
|
|
53
65
|
include Mongoid::Document
|
54
66
|
belongs_to_active_record :manufacturer
|
55
67
|
has_one_active_record :powerplant
|
56
|
-
|
68
|
+
has_many_active_record :variants
|
57
69
|
end
|
58
70
|
```
|
59
71
|
|
60
|
-
*Nota bene:* Consort currently provides only basic association accessors. It does not implement callbacks. Consort also does not currently implement many-to-many associations. I've rarely run into a situation where cross-ORM many-to-many associations make sense, and implementing them would require making opinionated decisions I don't care to make without community input. If this is something you
|
72
|
+
*Nota bene:* Consort currently provides only basic association accessors. It does not implement callbacks. Consort also does not currently implement many-to-many associations. I've rarely run into a situation where cross-ORM many-to-many associations make sense, and implementing them would require making opinionated decisions I don't care to make without community input. If this is something you find yourself needing immediately, you'll have to implement it yourself. (Pull requests and feedback are welcome.)
|
61
73
|
|
62
74
|
## Contributing
|
63
75
|
|
64
|
-
1. Fork it
|
76
|
+
1. [Fork it](https://github.com/cmattson/consort/fork)
|
65
77
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
78
|
3. No, seriously, create a branch. Call it `ravenous-monkey` for all I care, but create a branch.
|
67
79
|
4. Commit your changes (`git commit -am 'Add some feature'`)
|
@@ -72,7 +84,6 @@ Make sure you include tests! Tests are good. Tests are required. All hail tests.
|
|
72
84
|
|
73
85
|
Consort tests are built with Minitest; beyond that, I'm flexible. `Minitest::Unit` and `Minitest::Spec` are both fine.
|
74
86
|
|
75
|
-
For more details, see CONTRIBUTING.md.
|
76
87
|
|
77
88
|
## Author
|
78
89
|
|
data/consort.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "coveralls"
|
28
28
|
spec.add_development_dependency "sqlite3"
|
29
29
|
spec.add_development_dependency "pry"
|
30
|
-
spec.add_development_dependency
|
30
|
+
spec.add_development_dependency "combustion"
|
31
31
|
|
32
32
|
spec.add_runtime_dependency "activesupport", "~> 3.2"
|
33
33
|
spec.add_runtime_dependency "activerecord", "~> 3.2"
|
@@ -14,7 +14,7 @@ module Consort
|
|
14
14
|
CODE
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def has_many_mongoid(klass)
|
18
18
|
class_eval <<-CODE
|
19
19
|
def #{klass}
|
20
20
|
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
@@ -22,6 +22,12 @@ module Consort
|
|
22
22
|
CODE
|
23
23
|
end
|
24
24
|
|
25
|
+
# DEPRECATED. Pass through for now. Removed in 1.0.0.
|
26
|
+
def has_many_mongoids(klass)
|
27
|
+
ActiveSupport::Deprecation.warn 'Please use the singular has_many_mongoid instead.'
|
28
|
+
has_many_mongoid(klass)
|
29
|
+
end
|
30
|
+
|
25
31
|
def belongs_to_mongoid(klass)
|
26
32
|
class_eval <<-CODE
|
27
33
|
def #{klass}
|
data/lib/consort/mongoid.rb
CHANGED
@@ -11,14 +11,20 @@ module Consort
|
|
11
11
|
CODE
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def has_many_active_record(klass)
|
15
15
|
class_eval <<-CODE
|
16
16
|
def #{klass}
|
17
|
-
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
17
|
+
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
18
18
|
end
|
19
19
|
CODE
|
20
20
|
end
|
21
21
|
|
22
|
+
# DEPRECATED. Will be removed in 1.0.0.
|
23
|
+
def has_many_active_records(klass)
|
24
|
+
ActiveSupport::Deprecation.warn 'Please use the singular has_many_active_record instead.'
|
25
|
+
has_many_active_record(klass)
|
26
|
+
end
|
27
|
+
|
22
28
|
def belongs_to_active_record(klass)
|
23
29
|
class_eval <<-CODE
|
24
30
|
def #{klass}
|
data/lib/consort/version.rb
CHANGED
data/test/db/schema.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
ActiveRecord::Schema.define(:version => 0) do
|
2
2
|
|
3
|
-
create_table :ungulates, :
|
3
|
+
create_table :ungulates, force: true do |t|
|
4
4
|
t.column :name, :string
|
5
5
|
t.column :congo_id, :string
|
6
6
|
end
|
7
7
|
|
8
|
-
create_table :tongues, :
|
8
|
+
create_table :tongues, force: true do |t|
|
9
9
|
t.column :camel_id, :string
|
10
10
|
t.column :slimy, :boolean
|
11
11
|
end
|
12
12
|
|
13
|
-
create_table :humps, :
|
13
|
+
create_table :humps, force: true do |t|
|
14
14
|
t.column :camel_id, :string
|
15
15
|
t.column :number, :integer
|
16
16
|
t.column :size_mm, :integer
|
17
17
|
end
|
18
18
|
|
19
|
-
create_table :species, :
|
19
|
+
create_table :species, force: true do |t|
|
20
20
|
t.column :common_name, :string
|
21
21
|
t.column :scientific_name, :string
|
22
22
|
end
|
data/test/models.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# Testing of AR bindings with light testing of reverses
|
2
2
|
class Ungulate < ActiveRecord::Base
|
3
|
-
has_one_mongoid
|
4
|
-
|
5
|
-
belongs_to_mongoid
|
3
|
+
has_one_mongoid :mango
|
4
|
+
has_many_mongoid :bongos
|
5
|
+
belongs_to_mongoid :congo
|
6
6
|
end
|
7
7
|
|
8
8
|
class Mango
|
9
9
|
include Mongoid::Document
|
10
10
|
belongs_to_active_record :ungulate
|
11
11
|
|
12
|
-
field :ripeness,
|
13
|
-
field :ar_instance_id,
|
12
|
+
field :ripeness, type: Integer
|
13
|
+
field :ar_instance_id, type: Integer
|
14
14
|
end
|
15
15
|
|
16
16
|
class Bongo
|
17
17
|
include Mongoid::Document
|
18
18
|
belongs_to_active_record :ungulate
|
19
19
|
|
20
|
-
field :diameter,
|
21
|
-
field :number,
|
20
|
+
field :diameter, type: Integer
|
21
|
+
field :number, type: Integer
|
22
22
|
end
|
23
23
|
|
24
24
|
class Congo
|
@@ -32,7 +32,7 @@ end
|
|
32
32
|
class Camel
|
33
33
|
include Mongoid::Document
|
34
34
|
has_one_active_record :tongue
|
35
|
-
|
35
|
+
has_many_active_record :humps
|
36
36
|
belongs_to_active_record :species
|
37
37
|
|
38
38
|
field :name, type: String
|
@@ -47,5 +47,5 @@ class Hump < ActiveRecord::Base
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class Species < ActiveRecord::Base
|
50
|
-
|
50
|
+
has_many_mongoid :camels
|
51
51
|
end
|
data/test/test_active_record.rb
CHANGED
@@ -2,21 +2,27 @@ require 'minitest/autorun'
|
|
2
2
|
|
3
3
|
class TestActiveRecord < Minitest::Test
|
4
4
|
def setup
|
5
|
-
#@ungulate = Ungulate.new
|
6
5
|
end
|
7
6
|
|
8
7
|
def test_active_record_has_one_mongoid_defined
|
9
|
-
assert_equal
|
8
|
+
assert_equal 'method', defined? ActiveRecord::Base.has_one_mongoid
|
10
9
|
assert_equal true, ActiveRecord::Base.respond_to?('has_one_mongoid')
|
11
10
|
end
|
12
11
|
|
12
|
+
# New form going forward.
|
13
|
+
def test_active_record_has_many_mongoid_defined
|
14
|
+
assert_equal 'method', defined? ActiveRecord::Base.has_many_mongoid
|
15
|
+
assert_equal true, ActiveRecord::Base.respond_to?('has_many_mongoid')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Deprecated form still available.
|
13
19
|
def test_active_record_has_many_mongoids_defined
|
14
|
-
assert_equal
|
20
|
+
assert_equal 'method', defined? ActiveRecord::Base.has_many_mongoids
|
15
21
|
assert_equal true, ActiveRecord::Base.respond_to?('has_many_mongoids')
|
16
22
|
end
|
17
23
|
|
18
24
|
def test_active_record_belongs_to_mongoid_defined
|
19
|
-
assert_equal
|
25
|
+
assert_equal 'method', defined? ActiveRecord::Base.belongs_to_mongoid
|
20
26
|
assert_equal true, ActiveRecord::Base.respond_to?('belongs_to_mongoid')
|
21
27
|
end
|
22
28
|
|
@@ -26,7 +32,7 @@ class TestActiveRecord < Minitest::Test
|
|
26
32
|
assert_equal false, @u.respond_to?('mangos')
|
27
33
|
end
|
28
34
|
|
29
|
-
def
|
35
|
+
def test_has_many_mongoid
|
30
36
|
@u = Ungulate.new
|
31
37
|
assert_equal true, @u.respond_to?('bongos')
|
32
38
|
assert_equal false, @u.respond_to?('bongo')
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
plugin_test_dir = File.dirname(__FILE__)
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
+
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
4
8
|
require 'bundler/setup'
|
5
9
|
require 'pry'
|
6
10
|
|
@@ -12,9 +16,6 @@ require 'minitest/spec'
|
|
12
16
|
require 'minitest/pride'
|
13
17
|
require 'minitest/benchmark' if ENV['BENCH']
|
14
18
|
|
15
|
-
require 'coveralls'
|
16
|
-
Coveralls.wear!
|
17
|
-
|
18
19
|
require 'active_record'
|
19
20
|
require 'mongoid'
|
20
21
|
|
@@ -22,14 +23,12 @@ require 'consort'
|
|
22
23
|
|
23
24
|
require 'yaml'
|
24
25
|
require 'erb'
|
25
|
-
ActiveRecord::Base.configurations = YAML
|
26
|
-
ActiveRecord::Base.establish_connection(ENV[
|
26
|
+
ActiveRecord::Base.configurations = YAML.load(ERB.new(IO.read(plugin_test_dir + '/db/database.yml')).result)
|
27
|
+
ActiveRecord::Base.establish_connection(ENV['DB'] ||= 'sqlite3mem')
|
27
28
|
ActiveRecord::Migration.verbose = false
|
28
29
|
|
29
30
|
require 'combustion/database'
|
30
31
|
Combustion::Database.create_database(ActiveRecord::Base.configurations[ENV["DB"]])
|
31
|
-
load(File.join(plugin_test_dir,
|
32
|
-
|
33
|
-
|
34
|
-
require 'models'
|
32
|
+
load(File.join(plugin_test_dir, 'db', 'schema.rb'))
|
35
33
|
|
34
|
+
require 'models'
|
data/test/test_mongoid.rb
CHANGED
@@ -8,6 +8,10 @@ class TestMongoid < Minitest::Test
|
|
8
8
|
assert_equal true, Camel.respond_to?(:has_one_active_record)
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_mongoid_has_many_active_record_defined
|
12
|
+
assert_equal true, Camel.respond_to?(:has_many_active_record)
|
13
|
+
end
|
14
|
+
|
11
15
|
def test_mongoid_has_many_active_records_defined
|
12
16
|
assert_equal true, Camel.respond_to?(:has_many_active_records)
|
13
17
|
end
|
@@ -22,7 +26,7 @@ class TestMongoid < Minitest::Test
|
|
22
26
|
assert_equal false, @c.respond_to?('tongues')
|
23
27
|
end
|
24
28
|
|
25
|
-
def
|
29
|
+
def test_has_many_active_record
|
26
30
|
@c = Camel.new
|
27
31
|
assert_equal true, @c.respond_to?('humps')
|
28
32
|
assert_equal false, @c.respond_to?('hump')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Mattson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -205,7 +205,6 @@ files:
|
|
205
205
|
- CHANGELOG.md
|
206
206
|
- Gemfile
|
207
207
|
- LICENSE
|
208
|
-
- LICENSE.txt
|
209
208
|
- README.md
|
210
209
|
- Rakefile
|
211
210
|
- consort.gemspec
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Colin Mattson
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|