ransack_active_record_enhancer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +20 -0
- data/README.md +51 -0
- data/lib/ransack_active_record_enhancer.rb +20 -0
- data/lib/ransack_active_record_enhancer/configuration.rb +17 -0
- data/lib/ransack_active_record_enhancer/constants.rb +6 -0
- data/lib/ransack_active_record_enhancer/enhanced_where.rb +23 -0
- data/lib/ransack_active_record_enhancer/version.rb +3 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3f4e16e224677e9e5665f24b55005ad434c8482973c991c0c51315adeab22069
|
4
|
+
data.tar.gz: 799e548a8e87532d40470957eb7a41a34cc9efef9d50588188a04eafedb6d293
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: daf9495ee7ac5267dc812acddab8959c13e47b110331ea286f4a4ea20fb9e3ab3ec67ceb1f9e0bb482853463ae51c3d9e394b9bc2c6a240dcd9611876f6c34a1
|
7
|
+
data.tar.gz: b4975ae1c4ae8fc611fd9b7e0938b1b3e06527f022ec2104baf756cb3e39f843af5eb449e6fe8b57d790e0edf4f426b3242a5025cb22142c18185cbc044d80d7
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 []().
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# RansackActiveRecordEnhancer
|
2
|
+
|
3
|
+
RansackActiveRecordEnhancer simply enhances active record methods.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ransack_active_record_enhancer'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ransack_active_record_enhancer
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class ApplicationRecord < ActiveRecord::Base
|
25
|
+
include RansackActiveRecordEnhancer::EnhancedWhere
|
26
|
+
end
|
27
|
+
|
28
|
+
class User < ApplicationRecord
|
29
|
+
end
|
30
|
+
|
31
|
+
User.enhanced_where(email: 'johndoe@example.com', created_at_gteq: DateTime.now - 1.day, created_at_lteq: DateTime.now + 1.day).to_sql
|
32
|
+
# > "SELECT \"USERS\".* FROM \"USERS\" WHERE (\"USERS\".\"EMAIL\" = 'johndoe@example.com' AND \"USERS\".\"CREATED_AT\" >= '2018-05-22' AND \"USERS\".\"CREATED_AT\" <= '2018-05-24')"
|
33
|
+
```
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
See [contributing](CONTRIBUTING.md).
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.md).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
See [code of conduct](CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RansackActiveRecordEnhancer
|
2
|
+
class << self
|
3
|
+
def config
|
4
|
+
@config ||= Configuration.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure
|
8
|
+
yield config
|
9
|
+
end
|
10
|
+
|
11
|
+
def enhanced_where_method_name
|
12
|
+
config.enhancers[:enhanced_where][:method_name].downcase.to_sym
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'ransack_active_record_enhancer/version'
|
18
|
+
require 'ransack_active_record_enhancer/constants'
|
19
|
+
require 'ransack_active_record_enhancer/configuration'
|
20
|
+
require 'ransack_active_record_enhancer/enhanced_where'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RansackActiveRecordEnhancer
|
2
|
+
class Configuration
|
3
|
+
attr_reader :enhancers
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@enhancers = {
|
7
|
+
enhanced_where: {
|
8
|
+
method_name: :enhanced_where
|
9
|
+
}
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def enhancers=(options = {})
|
14
|
+
@enhancers.deep_merge!(options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RansackActiveRecordEnhancer
|
2
|
+
module EnhancedWhere
|
3
|
+
def self.included(klass)
|
4
|
+
klass.class_eval do
|
5
|
+
class << self
|
6
|
+
define_method RansackActiveRecordEnhancer.enhanced_where_method_name do |opts = :chain, *rest|
|
7
|
+
return super(opts, *rest) unless opts.is_a?(Hash)
|
8
|
+
|
9
|
+
options = opts.collect do |key, value|
|
10
|
+
predicate = value.is_a?(Array) ? :in : :eq
|
11
|
+
|
12
|
+
key = "#{key}_#{predicate}" unless RANSACK_PREDICATES.include?(key.to_s.split('_').last)
|
13
|
+
|
14
|
+
{ key.to_sym => value }
|
15
|
+
end.reduce(:merge)
|
16
|
+
|
17
|
+
ransack(options).result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ransack_active_record_enhancer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leonardo Falk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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: wonder-ruby-style
|
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: codeclimate-test-reporter
|
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: ransack
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Enhance active record methods with ransack.
|
98
|
+
email:
|
99
|
+
- leonardo.falk@hotmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- README.md
|
104
|
+
- LICENSE.md
|
105
|
+
files:
|
106
|
+
- LICENSE.md
|
107
|
+
- README.md
|
108
|
+
- lib/ransack_active_record_enhancer.rb
|
109
|
+
- lib/ransack_active_record_enhancer/configuration.rb
|
110
|
+
- lib/ransack_active_record_enhancer/constants.rb
|
111
|
+
- lib/ransack_active_record_enhancer/enhanced_where.rb
|
112
|
+
- lib/ransack_active_record_enhancer/version.rb
|
113
|
+
homepage: https://github.com/leonardofalk/ransack_active_record_enhancer
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.7.6
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Enhance active record methods with ransack.
|
137
|
+
test_files: []
|