activerecord-poro 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +10 -0
- data/activerecord-poro.gemspec +28 -0
- data/lib/active_record/poro.rb +33 -0
- data/lib/active_record/poro/version.rb +5 -0
- data/lib/activerecord-poro.rb +1 -0
- data/spec/active_record/poro_spec.rb +42 -0
- data/spec/spec_helper.rb +37 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c1bfa8eb48d2a697a21d02f80dc49b2ff6abffb
|
4
|
+
data.tar.gz: cd35dc7f40196e3c4b07b805dbccfeb32a581129
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd05c6b3007dd7b650ddf3eb50c9a3490b40f2a19ec965366bcb28569e48e6e1d29234f6f42528bbfdc7be1fa1090df9e9dc655195985c84f8bfa8a104d0af14
|
7
|
+
data.tar.gz: 7115743c542602682e9ab42373ae17134496c53a70c5fcc13658b9164613c8b56eb7b8036bde3cb74981431fe8dddc566289e40fa2c69c8f1508caec561f0b1b
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Eric J. Holmes
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# ActiveRecord::Poro
|
2
|
+
|
3
|
+
This gem allows for plain old ruby objects to have associations into your ActiveRecord models.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'activerecord-poro'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install activerecord-poro
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class User < ActiveRecord::Base
|
23
|
+
end
|
24
|
+
|
25
|
+
class Message < ActiveRecord::Base
|
26
|
+
end
|
27
|
+
|
28
|
+
class Activity
|
29
|
+
include Virtus.model
|
30
|
+
|
31
|
+
attribute :action, String
|
32
|
+
|
33
|
+
attribute :subject_type, String
|
34
|
+
attribute :subject_id, Integer
|
35
|
+
|
36
|
+
attribute :creator_type, String
|
37
|
+
attribute :creator_id, Integer
|
38
|
+
|
39
|
+
belongs_to :subject, polymorphic: true
|
40
|
+
belongs_to :creator, polymorphic: true
|
41
|
+
|
42
|
+
def initialize(*args)
|
43
|
+
@association_cache = {}
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
message = Message.create
|
49
|
+
user = User.create
|
50
|
+
|
51
|
+
activity = Activity.new(
|
52
|
+
action: 'message.sent',
|
53
|
+
creator_type: 'User',
|
54
|
+
creator_id: user.id,
|
55
|
+
subject_type: 'Message',
|
56
|
+
subject_id: message.id
|
57
|
+
)
|
58
|
+
|
59
|
+
activity.subject
|
60
|
+
# => #<Message @id=1>
|
61
|
+
|
62
|
+
activity.creator
|
63
|
+
# => #<User @id=1>
|
64
|
+
```
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_record/poro/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'activerecord-poro'
|
8
|
+
spec.version = ActiveRecord::Poro::VERSION
|
9
|
+
spec.authors = ['Eric J. Holmes']
|
10
|
+
spec.email = ['eric@ejholmes.net']
|
11
|
+
spec.description = %q{Associations for plain old ruby objects}
|
12
|
+
spec.summary = %q{Associations for plain old ruby objects}
|
13
|
+
spec.homepage = 'https://github.com/remind101/activerecord-poro'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'activerecord'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'virtus'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'sqlite3'
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_support/dependencies'
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_record/poro/version'
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module Poro
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include ActiveRecord::Reflection
|
9
|
+
include ActiveRecord::Associations
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def pluralize_table_names
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def generated_feature_methods
|
17
|
+
@generated_feature_methods ||= begin
|
18
|
+
mod = const_set(:GeneratedFeatureMethods, Module.new)
|
19
|
+
include mod
|
20
|
+
mod
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_autosave_association_callbacks(reflection)
|
25
|
+
# NOOP
|
26
|
+
end
|
27
|
+
|
28
|
+
def connection
|
29
|
+
ActiveRecord::Base.connection
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_record/poro'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveRecord::Poro do
|
4
|
+
let(:user) { User.create }
|
5
|
+
let(:message) { Message.create }
|
6
|
+
let(:activity_class) {
|
7
|
+
Class.new do
|
8
|
+
include Virtus.model
|
9
|
+
include ActiveRecord::Poro
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
@association_cache = {}
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
describe '#belongs_to' do
|
19
|
+
describe 'polymorphic' do
|
20
|
+
let(:activity) { activity_class.new(creator_id: user.id, creator_type: 'User') }
|
21
|
+
|
22
|
+
before do
|
23
|
+
activity_class.class_eval do
|
24
|
+
belongs_to :creator, polymorphic: true
|
25
|
+
|
26
|
+
attribute :creator_id, Integer
|
27
|
+
attribute :creator_type, String
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'loads the association' do
|
32
|
+
expect(activity.creator).to eq user
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'allows the association to be eager loaded' do
|
36
|
+
ActiveRecord::Associations::Preloader.new(activity, [:creator]).run
|
37
|
+
expect(activity.association(:creator)).to be_loaded
|
38
|
+
expect(activity.association(:creator).target).to eq user
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.require :default, :test
|
3
|
+
require 'virtus'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.order = 'random'
|
7
|
+
config.filter_run :focus => true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
end
|
10
|
+
|
11
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
12
|
+
# in spec/support/ and its subdirectories.
|
13
|
+
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
|
14
|
+
|
15
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
16
|
+
|
17
|
+
# Connect to an in-memory sqlite3 database
|
18
|
+
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3',
|
19
|
+
:database => ':memory:' )
|
20
|
+
|
21
|
+
# Create the minimal database schema necessary to reproduce the bug
|
22
|
+
ActiveRecord::Schema.define do
|
23
|
+
create_table "users" do |t|
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table "messages" do |t|
|
27
|
+
t.belongs_to :user
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class User < ActiveRecord::Base
|
32
|
+
has_many :messages
|
33
|
+
end
|
34
|
+
|
35
|
+
class Message < ActiveRecord::Base
|
36
|
+
belongs_to :user
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-poro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric J. Holmes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: virtus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Associations for plain old ruby objects
|
98
|
+
email:
|
99
|
+
- eric@ejholmes.net
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- activerecord-poro.gemspec
|
111
|
+
- lib/active_record/poro.rb
|
112
|
+
- lib/active_record/poro/version.rb
|
113
|
+
- lib/activerecord-poro.rb
|
114
|
+
- spec/active_record/poro_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
homepage: https://github.com/remind101/activerecord-poro
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.0.14
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Associations for plain old ruby objects
|
140
|
+
test_files:
|
141
|
+
- spec/active_record/poro_spec.rb
|
142
|
+
- spec/spec_helper.rb
|