activerecord_scoping_with_assoc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 287b18d59c6d64dc1ec94d77dcfc9439ec569fa7964d69e3ada39b7b2c4a990d
4
+ data.tar.gz: dcf39059fd6e2a75c9594d54e746faa22b04f620c3dfb194ce5961a8f531c78a
5
+ SHA512:
6
+ metadata.gz: 58cb8a5da82b2eec54ad89ec151720c75b09241e3af704dd860bb74cb4908bf5b20197f5279676ecfa34788914575a98f1287e28cd2e789799142f5e5d79c372
7
+ data.tar.gz: 1e5322a3ec3ae949a18ebe8315a4c7b42f5e988e39f4b4b844e8d3aba29680cb0492145320f4ed37991ba46b862e1e0b2b93ed9a578fd686595fae42e48fd1b2
@@ -0,0 +1,11 @@
1
+ .bundle/
2
+ .project
3
+ Gemfile.lock
4
+ coverage/
5
+ pkg/
6
+ spec/dummy/config/database.yml
7
+ spec/dummy/db/schema*.rb
8
+ spec/dummy/db/*.sqlite3
9
+ spec/dummy/log/*.log
10
+ spec/dummy/tmp/*
11
+ tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5
4
+ - 2.6
5
+ services:
6
+ - mysql
7
+ - postgresql
8
+ addons:
9
+ postgresql: "9.5"
10
+ env:
11
+ - DATABASE=sqlite
12
+ - DATABASE=mysql
13
+ - DATABASE=postgresql
14
+ gemfile:
15
+ - gemfiles/rails60.gemfile
16
+ before_script:
17
+ - cd spec/dummy
18
+ - bundle exec rake db:create db:migrate db:seed RAILS_ENV=test
19
+ - cd ../..
20
+ script:
21
+ - bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yoshikazu Kaneta
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # ActiveRecordScopingWithAssoc
2
+
3
+ Merge scoping to associations in the same way as activerecord5.
4
+
5
+ ## Dependencies
6
+
7
+ * ruby 2.5+
8
+ * activerecord 6.0
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'activerecord_scoping_with_assoc'
16
+ ```
17
+
18
+ Then execute:
19
+
20
+ $ bundle
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ Klass.where(...).scoping_with_assoc do
26
+ ...
27
+ end
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome at https://github.com/kanety/activerecord_scoping_with_assoc.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -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 'activerecord_scoping_with_assoc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord_scoping_with_assoc"
8
+ spec.version = ActiveRecordScopingWithAssoc::VERSION
9
+ spec.authors = ["Yoshikazu Kaneta"]
10
+ spec.email = ["kaneta@sitebridge.co.jp"]
11
+ spec.summary = %q{Merge scoping to associations}
12
+ spec.description = %q{Merge scoping to associations}
13
+ spec.homepage = "https://github.com/kanety/activerecord_scoping_with_assoc"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "activerecord", ">= 6.0"
21
+
22
+ spec.add_development_dependency "rails", ">= 6.0"
23
+ spec.add_development_dependency "mysql2"
24
+ spec.add_development_dependency "pg"
25
+ spec.add_development_dependency "sqlite3"
26
+ spec.add_development_dependency "rspec-rails"
27
+ spec.add_development_dependency "simplecov"
28
+ end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rails", "~> 6.0.0"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,4 @@
1
+ require 'activerecord_scoping_with_assoc/version'
2
+ require 'activerecord_scoping_with_assoc/association'
3
+ require 'activerecord_scoping_with_assoc/relation'
4
+ require 'activerecord_scoping_with_assoc/railtie' if defined?(Rails)
@@ -0,0 +1,11 @@
1
+ module ActiveRecordScopingWithAssoc
2
+ module Association
3
+ def target_scope
4
+ if Thread.current[KEY] && Thread.current[KEY][klass] == true
5
+ ActiveRecord::AssociationRelation.create(klass, self).merge!(klass.current_scope)
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module ActiveRecordScopingWithAssoc
2
+ class Railtie < Rails::Railtie
3
+ ActiveSupport.on_load :active_record do
4
+ ActiveRecord::Relation.send :include, ActiveRecordScopingWithAssoc::Relation
5
+ ActiveRecord::Associations::Association.prepend ActiveRecordScopingWithAssoc::Association
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveRecordScopingWithAssoc
2
+ KEY = :_activerecord_scoping_with_assoc
3
+
4
+ module Relation
5
+ def scoping_with_assoc
6
+ Thread.current[KEY] ||= {}
7
+ Thread.current[KEY][klass] = true
8
+ scoping { yield }
9
+ ensure
10
+ Thread.current[KEY] = nil
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveRecordScopingWithAssoc
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_scoping_with_assoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshikazu Kaneta
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-09 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: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '6.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mysql2
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: pg
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: sqlite3
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: rspec-rails
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
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Merge scoping to associations
112
+ email:
113
+ - kaneta@sitebridge.co.jp
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - activerecord_scoping_with_assoc.gemspec
126
+ - gemfiles/rails60.gemfile
127
+ - lib/activerecord_scoping_with_assoc.rb
128
+ - lib/activerecord_scoping_with_assoc/association.rb
129
+ - lib/activerecord_scoping_with_assoc/railtie.rb
130
+ - lib/activerecord_scoping_with_assoc/relation.rb
131
+ - lib/activerecord_scoping_with_assoc/version.rb
132
+ homepage: https://github.com/kanety/activerecord_scoping_with_assoc
133
+ licenses: []
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubygems_version: 3.0.3
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Merge scoping to associations
154
+ test_files: []