consort 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +5 -1
- data/.yardopts +2 -0
- data/CHANGELOG.md +5 -0
- data/README.md +39 -6
- data/consort.gemspec +10 -9
- data/gemfiles/Gemfile.rails-3.1.x +12 -0
- data/gemfiles/Gemfile.rails-4.0.x +12 -0
- data/lib/consort.rb +3 -2
- data/lib/consort/active_record/mongoid.rb +74 -0
- data/lib/consort/mongoid/active_record.rb +68 -0
- data/lib/consort/version.rb +1 -1
- data/test/test_active_record.rb +6 -1
- data/test/test_helper.rb +12 -4
- data/test/test_mongoid.rb +6 -1
- metadata +30 -12
- data/lib/consort/active_record.rb +0 -49
- data/lib/consort/mongoid.rb +0 -46
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDJkNmNjYjhjODY0ZmM3M2M1YTg5ODFhZDU1NDJlODhiODY1Y2U2NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGY3MGYwYThlMGRmZjczMjY0ZTQ2MjFiZmZkYzY2NjNlOWM4YWM5Yw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzRkNTA2ZmE5Yzc4ZmVkNTU5ZDE3ZmIzNTk4MmUwNmQwMDZkNDU0MmI4MjMx
|
10
|
+
NmZkMWYwMmQyM2Y3OWE5MjE4Y2JjMTY2ZGUzZTNiYjRiN2U5Y2I1YmZmNDdk
|
11
|
+
MjVjNmI2NDA4MzUyOTgzZmU5NTU0OGJhMjc1YWY2MWRlOWQyNTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDkyYmU4MTk0ODc3OWYzZjk5NGM2ZGI4N2UxNTIwZGVlZmE1MWM4NTc2ZjA5
|
14
|
+
ZTZlOGI3Mzg5MzI0OWYwMDVkZWU3Yzg3MTY0ODE4ZDI2ZTIxMWRlZTczODhj
|
15
|
+
ODMyY2ZmNTc5ODMyZDkzOTk1NTU3OTMzMmU2YWIxYTA0YjAzYjA=
|
data/.travis.yml
CHANGED
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,11 +9,11 @@ Mixing ActiveRecord and other ORMs like Mongoid? Need relationships between thos
|
|
9
9
|
|
10
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.
|
11
11
|
|
12
|
-
|
12
|
+
## Once More, With 50% Less Jargon
|
13
13
|
|
14
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
15
|
|
16
|
-
Consort allows you to define has_one
|
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 and ODM adapters, but ActiveRecord <-> Mongoid is what's written today.)
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
@@ -33,14 +33,18 @@ Or install it yourself as:
|
|
33
33
|
|
34
34
|
Ruby 1.9.3 or 2.0.0. Alternate VMs compatible with these versions should also work.
|
35
35
|
|
36
|
-
Ruby 1.8 is not supported.
|
36
|
+
Ruby 1.8 is not supported. Let the dead rest in peace!
|
37
37
|
|
38
38
|
### Rails Compatibility
|
39
39
|
|
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.
|
40
|
+
Consort currently targets Rails 3.2 (or, more accurately, ActiveSupport and ActiveRecord 3.2). Mongoid and several other ORM/ODM layers have not yet been updated for Rails 4, and most new and existing projects are continuing to use Rails 3.2 for now.
|
41
41
|
|
42
42
|
Rails 4 support is planned.
|
43
43
|
|
44
|
+
### Continuous Integration
|
45
|
+
|
46
|
+
Automated CI testing is performed against Ruby 1.9.3 and 2.0.0 using ActiveRecord and ActiveSupport 3.1, 3.2, and 4.0.
|
47
|
+
|
44
48
|
## Usage
|
45
49
|
|
46
50
|
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.
|
@@ -51,6 +55,7 @@ The relationship macros are designed to read cleanly:
|
|
51
55
|
* Airframe has many Mongoid variants
|
52
56
|
|
53
57
|
On an ActiveRecord model, you can define relationships with Mongoid:
|
58
|
+
|
54
59
|
```ruby
|
55
60
|
class Airframe < ActiveRecord::Base
|
56
61
|
belongs_to_mongoid :manufacturer
|
@@ -60,22 +65,50 @@ end
|
|
60
65
|
```
|
61
66
|
|
62
67
|
On a Mongoid model, you can define relationships with ActiveRecord:
|
68
|
+
|
63
69
|
```ruby
|
64
70
|
class Airframe
|
65
71
|
include Mongoid::Document
|
66
72
|
belongs_to_active_record :manufacturer
|
67
73
|
has_one_active_record :powerplant
|
68
74
|
has_many_active_record :variants
|
75
|
+
|
76
|
+
# Consort expects a foreign key field
|
77
|
+
field :manufacturer_id, type: Integer
|
69
78
|
end
|
70
79
|
```
|
71
80
|
|
72
|
-
|
81
|
+
### Unimplemented Features
|
82
|
+
There are several things Consort doesn't (currently) do, either because I haven't
|
83
|
+
seen them used when mixing object mappers, or because they may have horrible
|
84
|
+
unintended consequences.
|
85
|
+
|
86
|
+
This doesn't mean Consort **shouldn't** do them; if you have a use case for a
|
87
|
+
missing feature, feel free to implement it and send a pull request, or create an
|
88
|
+
issue with a feature request.
|
89
|
+
|
90
|
+
#### Many-to-Many Relationships
|
91
|
+
Consort doesn't support many-to-many relationships. I've rarely run into a
|
92
|
+
situation where they make sense in cross-ORM applications, and implementing them
|
93
|
+
would require making decisions like "where do we store them?".
|
94
|
+
|
95
|
+
#### Polymorphism
|
96
|
+
Also low on the list of use cases.
|
97
|
+
|
98
|
+
#### Callbacks
|
99
|
+
This falls into the potential horrible unintended consequences group.
|
100
|
+
|
101
|
+
Consort *does not* currently implement automatic callbacks (e.g. destroying a
|
102
|
+
Mongoid object automatically when its parent ActiveRecord object is destroyed). If
|
103
|
+
creating/altering/deleting an object from one object mapper should
|
104
|
+
create/alter/delete an associated object from a different object mapper, you
|
105
|
+
currently need to take care of this yourself.
|
73
106
|
|
74
107
|
## Contributing
|
75
108
|
|
76
109
|
1. [Fork it](https://github.com/cmattson/consort/fork)
|
77
110
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
-
3. No, seriously, create a branch. Call it `ravenous-monkey` for all I care, but create a branch.
|
111
|
+
3. No, seriously, create a branch. Please. Call it `ravenous-monkey` for all I care, but create a branch.
|
79
112
|
4. Commit your changes (`git commit -am 'Add some feature'`)
|
80
113
|
5. Push to the branch (`git push origin my-new-feature`)
|
81
114
|
6. Create new Pull Request
|
data/consort.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Consort::VERSION
|
9
9
|
spec.authors = ["Colin Mattson"]
|
10
10
|
spec.email = ["colinm@pixelcloud.us"]
|
11
|
-
spec.description = %q{Consort allows you to define relationships between various
|
11
|
+
spec.description = %q{Consort allows you to define relationships between various ORM/ODMs and access them similarly to ActiveRecord associations.}
|
12
12
|
spec.summary = %q{Ease integration between ActiveRecord and NoSQL solutions.}
|
13
13
|
spec.homepage = "https://github.com/cmattson/consort"
|
14
14
|
spec.license = "MIT"
|
@@ -18,18 +18,19 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler",
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "minitest"
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "mongoid",
|
23
|
+
spec.add_development_dependency "minitest", "~> 4.7"
|
24
|
+
spec.add_development_dependency "activesupport", "~> 3.2"
|
25
|
+
spec.add_development_dependency "activerecord", "~> 3.2"
|
26
|
+
spec.add_development_dependency "mongoid", "~> 3.1"
|
27
|
+
spec.add_development_dependency "simplecov"
|
27
28
|
spec.add_development_dependency "coveralls"
|
28
29
|
spec.add_development_dependency "sqlite3"
|
29
30
|
spec.add_development_dependency "pry"
|
30
31
|
spec.add_development_dependency "combustion"
|
31
32
|
|
32
|
-
spec.add_runtime_dependency
|
33
|
-
spec.add_runtime_dependency
|
34
|
-
spec.add_runtime_dependency
|
33
|
+
spec.add_runtime_dependency "activesupport", "~> 3.2"
|
34
|
+
spec.add_runtime_dependency "activerecord", "~> 3.2"
|
35
|
+
spec.add_runtime_dependency "mongoid", "~> 3.1"
|
35
36
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "bundler", "~> 1.3"
|
4
|
+
gem "rake"
|
5
|
+
gem "minitest", "~> 4.7"
|
6
|
+
gem "activesupport", "~> 3.1.12"
|
7
|
+
gem "activerecord", "~> 3.1.12"
|
8
|
+
gem "mongoid", "~> 3.0.0"
|
9
|
+
gem "coveralls"
|
10
|
+
gem "sqlite3"
|
11
|
+
gem "pry"
|
12
|
+
gem "combustion"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem "bundler", "~> 1.3"
|
4
|
+
gem "rake"
|
5
|
+
gem "minitest", "~> 4.7"
|
6
|
+
gem "activesupport", "~> 4.0.0"
|
7
|
+
gem "activerecord", "~> 4.0.0"
|
8
|
+
gem "mongoid", :git => 'https://github.com/mongoid/mongoid.git'
|
9
|
+
gem "coveralls"
|
10
|
+
gem "sqlite3"
|
11
|
+
gem "pry"
|
12
|
+
gem "combustion"
|
data/lib/consort.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Consort
|
2
|
+
##
|
3
|
+
# Defines methods on ActiveRecord objects for creating NoSQL
|
4
|
+
# relationships and accessing those related objects.
|
5
|
+
module ActiveRecord
|
6
|
+
module Mongoid
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
# Defines a `has_one` relationship with a Mongoid object.
|
11
|
+
# @param klass [Symbol]
|
12
|
+
# @example
|
13
|
+
# has_one_mongoid :dolphin
|
14
|
+
def has_one_mongoid(klass)
|
15
|
+
class_eval <<-CODE
|
16
|
+
def #{klass}
|
17
|
+
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
18
|
+
end
|
19
|
+
CODE
|
20
|
+
end
|
21
|
+
|
22
|
+
# Defines a `has_many` relationship with a Mongoid object.
|
23
|
+
# @param klass [Symbol]
|
24
|
+
# @example
|
25
|
+
# has_many_mongoid :unicorns
|
26
|
+
# @since 0.0.2
|
27
|
+
def has_many_mongoid(klass)
|
28
|
+
class_eval <<-CODE
|
29
|
+
def #{klass}
|
30
|
+
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
31
|
+
end
|
32
|
+
CODE
|
33
|
+
end
|
34
|
+
|
35
|
+
# @deprecated Use {#has_many_mongoid} instead. Will be removed in 1.0.0.
|
36
|
+
def has_many_mongoids(klass)
|
37
|
+
ActiveSupport::Deprecation.warn 'Please use the singular has_many_mongoid instead.'
|
38
|
+
has_many_mongoid(klass)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Defines a `belongs_to` relationship with a Mongoid object.
|
42
|
+
# An appropriate foreign key column (of type String) must exist on your model.
|
43
|
+
# @param klass [Symbol]
|
44
|
+
# @example Migration
|
45
|
+
# class AddMongoidFKeyToNarwhals < ActiveRecord::Migration
|
46
|
+
# def change
|
47
|
+
# add_column :narwhals, :pod_id, :string
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
# @example Model
|
51
|
+
# class Narwhal < ActiveRecord::Base
|
52
|
+
# belongs_to_mongoid :pod
|
53
|
+
# end
|
54
|
+
def belongs_to_mongoid(klass)
|
55
|
+
class_eval <<-CODE
|
56
|
+
def #{klass}
|
57
|
+
#{klass.to_s.classify}.where(id: #{klass.to_s.foreign_key})
|
58
|
+
end
|
59
|
+
CODE
|
60
|
+
end
|
61
|
+
|
62
|
+
# Allows easy validation of whether ActiveRecord to Mongoid bridge is loaded.
|
63
|
+
# @return [Boolean] `true` if bridge is loaded
|
64
|
+
def active_record_consorts_with_mongoid?
|
65
|
+
true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class ActiveRecord::Base
|
73
|
+
include Consort::ActiveRecord::Mongoid
|
74
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Consort
|
2
|
+
module Mongoid
|
3
|
+
module ActiveRecord
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
# Defines a `has_one` relationship with an ActiveRecord object.
|
8
|
+
# @param klass [Symbol]
|
9
|
+
# @example
|
10
|
+
# has_one_active_record :dolphin
|
11
|
+
def has_one_active_record(klass)
|
12
|
+
class_eval <<-CODE
|
13
|
+
def #{klass}
|
14
|
+
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
15
|
+
end
|
16
|
+
CODE
|
17
|
+
end
|
18
|
+
|
19
|
+
# Defines a `has_many` relationship with an ActiveRecord object.
|
20
|
+
# @param klass [Symbol]
|
21
|
+
# @example
|
22
|
+
# has_many_active_record :unicorns
|
23
|
+
# @since 0.0.2
|
24
|
+
def has_many_active_record(klass)
|
25
|
+
class_eval <<-CODE
|
26
|
+
def #{klass}
|
27
|
+
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
28
|
+
end
|
29
|
+
CODE
|
30
|
+
end
|
31
|
+
|
32
|
+
# @deprecated Use {#has_many_active_record} instead. Will be removed in 1.0.0.
|
33
|
+
def has_many_active_records(klass)
|
34
|
+
ActiveSupport::Deprecation.warn 'Please use the singular has_many_active_record instead.'
|
35
|
+
has_many_active_record(klass)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Defines a `belongs_to` relationship with an ActiveRecord object.
|
39
|
+
# An appropriate foreign key field must exist on your model.
|
40
|
+
# @param klass [Symbol]
|
41
|
+
# @example
|
42
|
+
# class Narwhal
|
43
|
+
# include Mongoid::Document
|
44
|
+
#
|
45
|
+
# belongs_to_active_record :pod
|
46
|
+
# field :pod_id, type: Integer
|
47
|
+
# end
|
48
|
+
def belongs_to_active_record(klass)
|
49
|
+
class_eval <<-CODE
|
50
|
+
def #{klass}
|
51
|
+
#{klass.to_s.classify}.where(id: #{klass.to_s.foreign_key})
|
52
|
+
end
|
53
|
+
CODE
|
54
|
+
end
|
55
|
+
|
56
|
+
# Allows easy validation of whether Mongoid to ActiveRecord bridge is loaded.
|
57
|
+
# @return [Boolean] `true` if bridge is loaded
|
58
|
+
def mongoid_consorts_with_active_record?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Mongoid::Document
|
67
|
+
include Consort::Mongoid::ActiveRecord
|
68
|
+
end
|
data/lib/consort/version.rb
CHANGED
data/test/test_active_record.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
|
3
|
-
class TestActiveRecord <
|
3
|
+
class TestActiveRecord < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
end
|
6
6
|
|
@@ -43,4 +43,9 @@ class TestActiveRecord < Minitest::Test
|
|
43
43
|
assert_equal true, @u.respond_to?('congo')
|
44
44
|
assert_equal false, @u.respond_to?('congos')
|
45
45
|
end
|
46
|
+
|
47
|
+
def test_implements_consorts
|
48
|
+
assert ActiveRecord::Base.respond_to?('active_record_consorts_with_mongoid?')
|
49
|
+
assert ActiveRecord::Base.active_record_consorts_with_mongoid?
|
50
|
+
end
|
46
51
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,8 +2,16 @@ plugin_test_dir = File.dirname(__FILE__)
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
|
5
|
+
require 'simplecov'
|
5
6
|
require 'coveralls'
|
6
|
-
|
7
|
+
|
8
|
+
if ENV["TRAVIS"]
|
9
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
10
|
+
end
|
11
|
+
|
12
|
+
SimpleCov.start do
|
13
|
+
add_filter '/test'
|
14
|
+
end
|
7
15
|
|
8
16
|
require 'bundler/setup'
|
9
17
|
require 'pry'
|
@@ -16,8 +24,8 @@ require 'minitest/spec'
|
|
16
24
|
require 'minitest/pride'
|
17
25
|
require 'minitest/benchmark' if ENV['BENCH']
|
18
26
|
|
19
|
-
require 'active_record'
|
20
|
-
require 'mongoid'
|
27
|
+
# require 'active_record'
|
28
|
+
# require 'mongoid'
|
21
29
|
|
22
30
|
require 'consort'
|
23
31
|
|
@@ -31,4 +39,4 @@ require 'combustion/database'
|
|
31
39
|
Combustion::Database.create_database(ActiveRecord::Base.configurations[ENV["DB"]])
|
32
40
|
load(File.join(plugin_test_dir, 'db', 'schema.rb'))
|
33
41
|
|
34
|
-
require 'models'
|
42
|
+
require 'models'
|
data/test/test_mongoid.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
|
3
|
-
class TestMongoid <
|
3
|
+
class TestMongoid < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
end
|
6
6
|
|
@@ -36,5 +36,10 @@ class TestMongoid < Minitest::Test
|
|
36
36
|
@c = Camel.new
|
37
37
|
assert_equal true, @c.respond_to?('species')
|
38
38
|
end
|
39
|
+
|
40
|
+
def test_implements_consorts
|
41
|
+
assert Camel.respond_to?('mongoid_consorts_with_active_record?')
|
42
|
+
assert Camel.mongoid_consorts_with_active_record?
|
43
|
+
end
|
39
44
|
|
40
45
|
end
|
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.3
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,18 +42,18 @@ dependencies:
|
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '4.7'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '4.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: activerecord
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: coveralls
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,8 +206,8 @@ dependencies:
|
|
192
206
|
- - ~>
|
193
207
|
- !ruby/object:Gem::Version
|
194
208
|
version: '3.1'
|
195
|
-
description: Consort allows you to define relationships between various
|
196
|
-
them similarly to ActiveRecord associations.
|
209
|
+
description: Consort allows you to define relationships between various ORM/ODMs and
|
210
|
+
access them similarly to ActiveRecord associations.
|
197
211
|
email:
|
198
212
|
- colinm@pixelcloud.us
|
199
213
|
executables: []
|
@@ -202,15 +216,18 @@ extra_rdoc_files: []
|
|
202
216
|
files:
|
203
217
|
- .gitignore
|
204
218
|
- .travis.yml
|
219
|
+
- .yardopts
|
205
220
|
- CHANGELOG.md
|
206
221
|
- Gemfile
|
207
222
|
- LICENSE
|
208
223
|
- README.md
|
209
224
|
- Rakefile
|
210
225
|
- consort.gemspec
|
226
|
+
- gemfiles/Gemfile.rails-3.1.x
|
227
|
+
- gemfiles/Gemfile.rails-4.0.x
|
211
228
|
- lib/consort.rb
|
212
|
-
- lib/consort/active_record.rb
|
213
|
-
- lib/consort/mongoid.rb
|
229
|
+
- lib/consort/active_record/mongoid.rb
|
230
|
+
- lib/consort/mongoid/active_record.rb
|
214
231
|
- lib/consort/version.rb
|
215
232
|
- test/db/database.yml
|
216
233
|
- test/db/schema.rb
|
@@ -249,3 +266,4 @@ test_files:
|
|
249
266
|
- test/test_active_record.rb
|
250
267
|
- test/test_helper.rb
|
251
268
|
- test/test_mongoid.rb
|
269
|
+
has_rdoc:
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Consort
|
2
|
-
##
|
3
|
-
# Defines instance methods on ActiveRecord objects for defining NoSQL
|
4
|
-
# relationships and accessing those related objects.
|
5
|
-
module ActiveRecord
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def has_one_mongoid(klass)
|
10
|
-
class_eval <<-CODE
|
11
|
-
def #{klass}
|
12
|
-
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
13
|
-
end
|
14
|
-
CODE
|
15
|
-
end
|
16
|
-
|
17
|
-
def has_many_mongoid(klass)
|
18
|
-
class_eval <<-CODE
|
19
|
-
def #{klass}
|
20
|
-
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
21
|
-
end
|
22
|
-
CODE
|
23
|
-
end
|
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
|
-
|
31
|
-
def belongs_to_mongoid(klass)
|
32
|
-
class_eval <<-CODE
|
33
|
-
def #{klass}
|
34
|
-
#{klass.to_s.classify}.where(id: #{klass.to_s.foreign_key})
|
35
|
-
end
|
36
|
-
CODE
|
37
|
-
end
|
38
|
-
|
39
|
-
def active_record_consorts_with_mongoid?
|
40
|
-
true
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class ActiveRecord::Base
|
48
|
-
include Consort::ActiveRecord
|
49
|
-
end
|
data/lib/consort/mongoid.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module Consort
|
2
|
-
module Mongoid
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
module ClassMethods
|
6
|
-
def has_one_active_record(klass)
|
7
|
-
class_eval <<-CODE
|
8
|
-
def #{klass}
|
9
|
-
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
10
|
-
end
|
11
|
-
CODE
|
12
|
-
end
|
13
|
-
|
14
|
-
def has_many_active_record(klass)
|
15
|
-
class_eval <<-CODE
|
16
|
-
def #{klass}
|
17
|
-
#{klass.to_s.classify}.where(#{name.foreign_key}: id)
|
18
|
-
end
|
19
|
-
CODE
|
20
|
-
end
|
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
|
-
|
28
|
-
def belongs_to_active_record(klass)
|
29
|
-
class_eval <<-CODE
|
30
|
-
def #{klass}
|
31
|
-
#{klass.to_s.classify}.where(id: #{klass.to_s.foreign_key})
|
32
|
-
end
|
33
|
-
CODE
|
34
|
-
end
|
35
|
-
|
36
|
-
def mongoid_consorts_with_active_record?
|
37
|
-
true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
module Mongoid::Document
|
45
|
-
include Consort::Mongoid
|
46
|
-
end
|