active_record_or_scope 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/active_record_or_scope.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/active_record_or_scope.rb +4 -0
- data/lib/active_record_or_scope/querying.rb +7 -0
- data/lib/active_record_or_scope/railtie.rb +8 -0
- data/lib/active_record_or_scope/relation.rb +15 -0
- data/lib/active_record_or_scope/version.rb +3 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f78c9fbe07346f2f524381f5598f5ae17fe47235
|
4
|
+
data.tar.gz: 77c563c17cfd1f2ceb1d0db5a8a1d704636ff9cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bac9bcc12fb2cb7964ee4af6554fe454521259e598ad8068bc0b7d60163894d89ae2bcb4a12b44d51d8db5be4120aff716be7fbb5703b6ec50209a46fdf0c9d6
|
7
|
+
data.tar.gz: 245ec9a7e28ccf501d9141434b843f1a6b2b06a3b5d7262808f5216e8dfd11fccf786aba818fa6ee4df7d27da82c31c85b3338eaf5f2994f0624dc666a0ece44
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# ActiveRecordOrScope
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/jobteaser/active_record_or_scope.svg?branch=master)](https://travis-ci.org/jobteaser/active_record_or_scope)
|
4
|
+
[![Code Climate](https://codeclimate.com/repos/58667f4a7b31a36aa70043b2/badges/2a5ab1c24ec5e2c9cb55/gpa.svg)](https://codeclimate.com/repos/58667f4a7b31a36aa70043b2/feed)
|
5
|
+
|
6
|
+
This gem allows chaining ActiveRecord scopes with OR instead of the default AND
|
7
|
+
|
8
|
+
The implementation is stolen from https://coderwall.com/p/lsdnsw/chain-rails-scopes-with-or
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'active_record_or_scope'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install active_record_or_scope
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
users = User.where_any(
|
30
|
+
User.where(name: "Bob"),
|
31
|
+
User.where(name: "Bobby"),
|
32
|
+
User.where(name: "Bobbie")
|
33
|
+
)
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jobteaser/active_record_or_scope.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_record_or_scope/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "active_record_or_scope"
|
8
|
+
spec.version = ActiveRecordOrScope::VERSION
|
9
|
+
spec.authors = ["David Ruyer"]
|
10
|
+
spec.email = ["david.ruyer@jobteaser.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Allow chaining active record scopes with OR.}
|
13
|
+
spec.description = %q{Allow chaining active record scopes with OR.}
|
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 "rails", "> 4.2"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "activerecord-nulldb-adapter", "~> 0.3.0"
|
26
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "active_record_or_scope"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
module ActiveRecordOrScope
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "railtie.configure_rails_initialization" do
|
4
|
+
ActiveRecord::Relation.send(:include, ActiveRecordOrScope::Relation)
|
5
|
+
ActiveRecord::Querying.send(:include, ActiveRecordOrScope::Querying)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecordOrScope
|
2
|
+
module Relation
|
3
|
+
def where_any(*scopes)
|
4
|
+
# Handle both scopes and scope names
|
5
|
+
scopes = scopes.map { |s| s.is_a?(Symbol) ? model.send(s) : s }
|
6
|
+
|
7
|
+
subscope = scopes.
|
8
|
+
map { |s| s.arel.constraints.reduce(:and) }.
|
9
|
+
map { |cc| Arel::Nodes::Grouping.new(cc) }.
|
10
|
+
reduce(:or)
|
11
|
+
|
12
|
+
where(subscope).tap { |sc| sc.bind_values += scopes.flat_map(&:bind_values) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_or_scope
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Ruyer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
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.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord-nulldb-adapter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.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.3.0
|
83
|
+
description: Allow chaining active record scopes with OR.
|
84
|
+
email:
|
85
|
+
- david.ruyer@jobteaser.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- active_record_or_scope.gemspec
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/active_record_or_scope.rb
|
99
|
+
- lib/active_record_or_scope/querying.rb
|
100
|
+
- lib/active_record_or_scope/railtie.rb
|
101
|
+
- lib/active_record_or_scope/relation.rb
|
102
|
+
- lib/active_record_or_scope/version.rb
|
103
|
+
homepage:
|
104
|
+
licenses: []
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.6.7
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Allow chaining active record scopes with OR.
|
126
|
+
test_files: []
|