association_scope 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68f9bb59cba6aef5a515e5e98bc1d2142be093806189a34afabd69ae6c644e1a
4
- data.tar.gz: 4fcc7b908d68b66c9225538132018ca9dd0925a8ba6ab5c634df5629cebc11cc
3
+ metadata.gz: b6737d583c54a2ce44c51f9313544bc2b73d5d083b86fa502b6e82bbca3c48d1
4
+ data.tar.gz: b85b28120cf9b7ac32a92f47db2ce4526391734188e9c13fcdfcb0762c177ba3
5
5
  SHA512:
6
- metadata.gz: da819d457189fb70dc3b4cd4f09af01c6a3547c8c5f5fa36a38efd4bf01f7c65c2110e4852d91ccc857a4965ce19c0b64f6425ab7034f1077c65a291668e1bc9
7
- data.tar.gz: 956f163600f9afcc845fe29f3d621661538b529cea40e84c2ba32fede3356760a81692c11ed6500de436aa4b52f9533c4e18649abadc34d58f915b9f9d08187f
6
+ metadata.gz: 162342ebf690b58e11a7ebb201073ac17bbeec4bd57e4b51c5f88a1ee2b1077182e98430e604d343fc31a237f615cafd7a736fcf99beb700dd4ee004d401d74f
7
+ data.tar.gz: 17e05e72a62217351f2d7bca06d6e0d2477ee9445df53cfb16681e728630cca3e6b2309b490fb50d6e5d6d175e1e0d7ecbb65fd81889eb54cdc714ff219006a9
data/README.md CHANGED
@@ -43,11 +43,11 @@ $ gem install association_scope
43
43
  ```
44
44
 
45
45
  ## Usage
46
- After installation you can use `acts_as_association_scope` in your models:
46
+ After installation you can use `has_association_scope_on` in your models:
47
47
  ```ruby
48
48
  class Topic < ApplicationRecord
49
49
  belongs_to :user
50
- acts_as_association_scope
50
+ has_association_scope_on [:user]
51
51
  end
52
52
  ```
53
53
  Now you can use your associations as scopes and chain other scopes with them.
@@ -59,22 +59,22 @@ to retrieve the users of all of the topics of your application.
59
59
 
60
60
  ## Known Issues
61
61
  * This gem works with `reflections`.
62
- To make this work, the `acts_as_association_scope` call has to be below your association definitions.
62
+ To make this work, the `has_association_scope_on` call has to be below your association definitions.
63
63
  ```ruby
64
64
  # won't work
65
65
  class Topic
66
- acts_as_association_scope
66
+ has_association_scope_on [:user]
67
67
  belongs_to :user
68
68
  end
69
69
 
70
70
  # works
71
71
  class Topic
72
72
  belongs_to :user
73
- acts_as_association_scope
73
+ has_association_scope_on [:user]
74
74
  end
75
75
  ```
76
- * Database views do not have a primary key.
77
- To use `distinct` on rows, all values of this row must be of types other than json.
76
+ * Does not work for tables without primary key.
77
+ * To use `distinct` on rows, all values of this row must be of types other than JSON.
78
78
  Workaround: Migrate JSON columns to JSONB.
79
79
  * Error messages are not raised during application start, but on first instantiation, because of the order in which classes are loaded.
80
80
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AssociationScope
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -15,15 +15,9 @@ end
15
15
 
16
16
  module ActiveRecord
17
17
  class Base
18
- def self.acts_as_association_scope(only: reflections.keys, except: [])
19
- # Apply given filters.
20
- # Don't be picky about singular or plural.
21
- raise ArgumentError, "Don't use :only and :except together!" unless only == reflections.keys || except == []
22
-
23
- only = only.map { |o| o.to_s }
24
- except = except.map { |e| e.to_s }
25
-
26
- ::AssociationScope::Scope.inject_scopes(self, only - except)
18
+ def self.has_association_scope_on(models)
19
+ models = models.map(&:to_s)
20
+ ::AssociationScope::Scope.inject_scopes(self, models)
27
21
  end
28
22
  end
29
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: association_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - datae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-06 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.2.15
110
+ rubygems_version: 3.1.4
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: AssociationScope adds useful scopes targeting Associations in ActiveRecord.