active_record-associated_object 0.5.0 → 0.5.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b973496c3658defdee08fb40292bad58fadbc743a732cface722c40f8b8152c
|
4
|
+
data.tar.gz: c6a3758599c0f5ce22470c18c23c958ebf05827a7f52ae0d07507cbd4b8b6346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57db29d169ee310087c539e1eb64ccce3bdeb6a98bdb7532723db4f90656140d521c9925efb3aa17782cd84b3e1906dfaaf0cd6dd72d69ad54e90b159a423547
|
7
|
+
data.tar.gz: dca66954be7f3e84ea76010e7714366532c506eb3ab02c1174bd47122ecce0af5223656ee11ed425d962d86b5a443ce69b95a187d40318ff555f497103df88ff
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -44,11 +44,47 @@ class Post::Publisher < ActiveRecord::AssociatedObject
|
|
44
44
|
end
|
45
45
|
```
|
46
46
|
|
47
|
-
###
|
47
|
+
### Namespaced models
|
48
48
|
|
49
|
-
|
49
|
+
If you have a namespaced Active Record like this:
|
50
50
|
|
51
|
-
|
51
|
+
```ruby
|
52
|
+
# app/models/post/comment.rb
|
53
|
+
class Post::Comment < ApplicationRecord
|
54
|
+
belongs_to :post
|
55
|
+
|
56
|
+
has_object :rating
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
You can define the associated object in the same way it was done for `Post::Publisher` above, within the `Post::Comment` namespace:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# app/models/post/comment/rating.rb
|
64
|
+
class Post::Comment::Rating < ActiveRecord::AssociatedObject
|
65
|
+
def great?
|
66
|
+
# A `comment` method is generated to access the associated comment. There's also a `record` alias available.
|
67
|
+
comment.author.subscriber_of? comment.post.author
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
### Composite primary keys
|
73
|
+
|
74
|
+
We support Active Record models with composite primary keys out of the box.
|
75
|
+
|
76
|
+
Just setup the associated objects like the above examples and you've got GlobalID/Active Job and Kredis support automatically.
|
77
|
+
|
78
|
+
### Remove Active Job boilerplate with `performs`
|
79
|
+
|
80
|
+
If you also bundle [`active_job-performs`](https://github.com/kaspth/active_job-performs) in your Gemfile like this:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
gem "active_job-performs"
|
84
|
+
gem "active_record-associated_object"
|
85
|
+
```
|
86
|
+
|
87
|
+
Every associated object now has access to the `performs` macro, so you can do this:
|
52
88
|
|
53
89
|
```ruby
|
54
90
|
class Post::Publisher < ActiveRecord::AssociatedObject
|
@@ -64,7 +100,7 @@ class Post::Publisher < ActiveRecord::AssociatedObject
|
|
64
100
|
end
|
65
101
|
```
|
66
102
|
|
67
|
-
is equivalent to:
|
103
|
+
which is equivalent to this:
|
68
104
|
|
69
105
|
```ruby
|
70
106
|
class Post::Publisher < ActiveRecord::AssociatedObject
|
@@ -97,6 +133,8 @@ class Post::Publisher < ActiveRecord::AssociatedObject
|
|
97
133
|
end
|
98
134
|
```
|
99
135
|
|
136
|
+
See the `ActiveJob::Performs` README for more details.
|
137
|
+
|
100
138
|
### Passing callbacks onto the associated object
|
101
139
|
|
102
140
|
`has_object` accepts a hash of callbacks to pass.
|
@@ -26,9 +26,5 @@ Gem::Specification.new do |spec|
|
|
26
26
|
end
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
# Uncomment to register a new dependency of your gem
|
30
29
|
spec.add_dependency "activerecord", ">= 6.1"
|
31
|
-
|
32
|
-
# For more information and examples about making a new gem, check out our
|
33
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
34
30
|
end
|
@@ -3,17 +3,17 @@ class ActiveRecord::AssociatedObject::Railtie < Rails::Railtie
|
|
3
3
|
config.after_initialize do
|
4
4
|
ActiveRecord::AssociatedObject.include Kredis::Attributes if defined?(Kredis)
|
5
5
|
ActiveRecord::AssociatedObject.include GlobalID::Identification if defined?(GlobalID)
|
6
|
-
|
7
|
-
ActiveSupport.on_load :active_job do
|
8
|
-
require "active_job/performs"
|
9
|
-
ActiveRecord::AssociatedObject.extend ActiveJob::Performs
|
10
|
-
rescue LoadError
|
11
|
-
# We haven't bundled active_job-performs, so we're continuing without it.
|
12
|
-
end
|
13
6
|
end
|
14
7
|
end
|
15
8
|
|
16
9
|
initializer "object_association.setup" do
|
10
|
+
ActiveSupport.on_load :active_job do
|
11
|
+
require "active_job/performs"
|
12
|
+
ActiveRecord::AssociatedObject.extend ActiveJob::Performs
|
13
|
+
rescue LoadError
|
14
|
+
# We haven't bundled active_job-performs, so we're continuing without it.
|
15
|
+
end
|
16
|
+
|
17
17
|
ActiveSupport.on_load :active_record do
|
18
18
|
require "active_record/associated_object/object_association"
|
19
19
|
extend ActiveRecord::AssociatedObject::ObjectAssociation
|
@@ -2,7 +2,7 @@ class ActiveRecord::AssociatedObject
|
|
2
2
|
class << self
|
3
3
|
def inherited(klass)
|
4
4
|
record_klass = klass.module_parent
|
5
|
-
record_name = klass.module_parent_name.underscore
|
5
|
+
record_name = klass.module_parent_name.demodulize.underscore
|
6
6
|
attribute_name = klass.to_s.demodulize.underscore.to_sym
|
7
7
|
|
8
8
|
unless record_klass.respond_to?(:descends_from_active_record?) && record_klass.descends_from_active_record?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-associated_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Timm Hansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|