active_record-ingress 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/lib/active_record/ingress/base.rb +1 -1
- data/lib/active_record/ingress/proxy.rb +1 -1
- data/lib/active_record/ingress/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32c4506e99cbf7645054306b1be5573f37ac6adbe517ea72895d9fa7f614b6f1
|
4
|
+
data.tar.gz: 9156ee99f0847c24ac0dd38d279cbb2f45686cec85623fd292ec39a074e39623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '078b9c1d9ee5c854054788aa3cf08d2e4ab24cf81c534ee2d49c3f91367b10a964f4a8dd1a6d3edf01147f31bb2bdb59a2dfce6534a9cf5648e2775cf4be9f83'
|
7
|
+
data.tar.gz: b8f16031704f6dd1fe81d8ec6b5c1b389d9aec74a587921f35c76dd8df72b39b3905207005e350eb7e35855f5023a4c3340c4a0afdf01bf31347a23314aa4c75
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,11 +6,11 @@ Pass control of Active Record methods to a dedicated object.
|
|
6
6
|
|
7
7
|
`ActiveRecord::Ingress` adds proxy forwarding method `ingressed` to any `ActiveRecord::Base` instance.
|
8
8
|
|
9
|
-
So `post.ingressed.update(title: "Updated title")` would look up a `Post::
|
9
|
+
So `post.ingressed.update(title: "Updated title")` would look up a `Post::Ingressed::Update` class, instance and execute its `perform` method:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
# app/models/post/
|
13
|
-
class Post::
|
12
|
+
# app/models/post/ingressed/update.rb
|
13
|
+
class Post::Ingressed::Update < ActiveRecord::Ingress::Base
|
14
14
|
# Each ingress has `params`, containing any passed keyword arguments.
|
15
15
|
# This extracts `params[:title]` and Ruby's keyword arguments handling will prevent accepting other arguments.
|
16
16
|
def perform(title:)
|
@@ -22,8 +22,8 @@ end
|
|
22
22
|
Ingresses can be used to create other forwarding too. Here, a `post.ingressed.prepare` is added:
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
# app/models/post/
|
26
|
-
class Post::
|
25
|
+
# app/models/post/ingressed/prepare.rb
|
26
|
+
class Post::Ingressed::Publish < ActiveRecord::Ingress::Base
|
27
27
|
def perform
|
28
28
|
# Forwards to `record.transaction`
|
29
29
|
transaction do
|
@@ -9,7 +9,7 @@ class ActiveRecord::Ingress::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.inherited(klass)
|
12
|
-
if alias_name = klass.module_parent_name.chomp("::
|
12
|
+
if alias_name = klass.module_parent_name.chomp("::Ingressed").underscore.presence
|
13
13
|
alias_method alias_name, :record
|
14
14
|
end
|
15
15
|
end
|
@@ -11,6 +11,6 @@ class ActiveRecord::Ingress::Proxy
|
|
11
11
|
attr_reader :__record__
|
12
12
|
|
13
13
|
def find_record_ingress_named(name)
|
14
|
-
"#{__record__.class.name}::
|
14
|
+
"#{__record__.class.name}::Ingressed::#{name.to_s.classify}".constantize
|
15
15
|
end
|
16
16
|
end
|