association_scope 0.1.0 → 0.3.2

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: 3cdd5ffca0653bd30600b32060a42de12505e41af7beae5a4faf750e95189925
4
- data.tar.gz: ce11c4a40bf02a01ca03e7d06ababdda30bc7c01012cd7b91241a2101ec19d70
3
+ metadata.gz: c4e530681dac428e3085f151e36a1a44a1f04a82b7da9df1be7e76fd3d02b80e
4
+ data.tar.gz: 05e2cf1a4c61eaef59bf93933827c118fa945be2f60a7079b1cd937e013259b7
5
5
  SHA512:
6
- metadata.gz: 8e380d107ae796069965a993e4ef4c375caea859450e018dffd0f0f53cea917696f7e4fcfd34f556d5b0e0d805e33ad4590cb1acdba115e76691f96884d43f8a
7
- data.tar.gz: b54e0f129fb76f8815c19997e7fdfe3b130bd316c38d4085f566592bfa10d2b3b1b37ecc4a416faa35e8d3d7e681ed7e2849b588955b7c207b5e380ee9403301
6
+ metadata.gz: 03e14bf3ca5db469c9e253dead3b9953f13afc4f39bb485bd48dac4c7b549dfa850f9933ffe9045a6ee97543ea883b35d264f5956fac01d93156f66ebd4919e2
7
+ data.tar.gz: ad322f4d8fe5a3e2860f421216f79bf4c129d652b0466c234a47970a4327c23659651cc1bfb4e344f7fa75356b3afac768eac08a272873a71201ca76a6cb1671
data/README.md CHANGED
@@ -29,7 +29,7 @@ When you have this problem, the AssociationScope gem is for you!
29
29
  Add this line to your application's Gemfile:
30
30
 
31
31
  ```ruby
32
- gem 'association_scope', git: 'https://github.com/datae95/association_scope', branch: :main
32
+ gem 'association_scope'
33
33
  ```
34
34
 
35
35
  And then execute:
@@ -37,42 +37,50 @@ And then execute:
37
37
  $ bundle
38
38
  ```
39
39
 
40
+ Or install it yourself as:
41
+ ```bash
42
+ $ gem install association_scope
43
+ ```
44
+
40
45
  ## Usage
41
- 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:
42
47
  ```ruby
43
48
  class Topic < ApplicationRecord
44
49
  belongs_to :user
45
- acts_as_association_scope
50
+ has_association_scope_on [:user]
46
51
  end
47
52
  ```
48
53
  Now you can use your associations as scopes and chain other scopes with them.
49
- When you have the classes `User` with many `Topic`s and every `Topic` has many `Post`s with many `Comment`s and all of them use `acts_as_association_scope`, you can write
54
+ You can write
50
55
  ```ruby
51
- User.first.topics.posts.comments
56
+ Topic.all.users
52
57
  ```
53
- to retrieve all comments of all posts of all topics of your first user.
58
+ to retrieve the users of all of the topics of your application.
54
59
 
55
60
  ## Known Issues
56
61
  * This gem works with `reflections`.
57
- 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.
58
63
  ```ruby
59
64
  # won't work
60
65
  class Topic
61
- acts_as_association_scope
66
+ has_association_scope_on [:user]
62
67
  belongs_to :user
63
68
  end
64
69
 
65
70
  # works
66
71
  class Topic
67
72
  belongs_to :user
68
- acts_as_association_scope
73
+ has_association_scope_on [:user]
69
74
  end
70
75
  ```
71
- * Database views do not have a primary key.
72
- 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.
73
78
  Workaround: Migrate JSON columns to JSONB.
74
79
  * Error messages are not raised during application start, but on first instantiation, because of the order in which classes are loaded.
75
80
 
76
81
  ## Development
77
- Clone the app and run `bundle`.
78
- To use `rails console` you have to navigate to the dummy application `cd spec/dummy`.
82
+ Clone this repository and run `bundle`.
83
+ To use `rails console` you have to navigate to the dummy application
84
+ ```bash
85
+ $ cd spec/dummy
86
+ ```
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AssociationScope
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.2"
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,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: association_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.2
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-01 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
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 6.1.4
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 6.1.4
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: standard
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.1.6
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -45,13 +45,27 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.9.26
48
- type: :runtime
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
54
  version: 0.9.26
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.10'
55
69
  description: AssociationScope adds useful scopes targeting Associations in ActiveRecord.
56
70
  email:
57
71
  - accounts@datae.de