ransack-enum 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rspec +3 -0
- data/.rubocop.yml +2 -11
- data/CHANGELOG.md +6 -0
- data/Gemfile +7 -1
- data/README.md +2 -2
- data/lib/ransack/enum.rb +2 -7
- data/lib/ransack/enum/adapters/active_record.rb +0 -10
- data/lib/ransack/enum/adapters/active_record/base.rb +18 -18
- data/lib/ransack/enum/configuration.rb +10 -6
- data/lib/ransack/enum/version.rb +1 -1
- data/ransack-enum.gemspec +18 -23
- metadata +5 -62
- data/.travis.yml +0 -7
- data/lib/ransack/enum/adapters.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d29a6d9f1aeb5b49f746c0c16e41b4690ebe4070f90fa5186572927b8ac2ee
|
4
|
+
data.tar.gz: a2358d2de52e1297aa65ef24c8a3a4529ff484e657716b7777d670483f9608b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64372e91b20d14ccf56ee0567f2aecc9940e2d39c83ca505173a49cea70dc6083fdc6586882c9608e2225d55ac46e8c9009e9e689bb2c5ec6ced8d9934cf7ea1
|
7
|
+
data.tar.gz: a3d1790361f9886debedc89d336cab5fea1eb4e17a4faa216c76262dcdc32535666b213bf1b1a60e62db9e53635b47f08a6f7977a1324275a8306767991d6708
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rubocop.yml
CHANGED
@@ -1,14 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
|
3
|
-
Exclude:
|
4
|
-
- Gemfile
|
5
|
-
- Gemfile.lock
|
6
|
-
- ransack-enum.gemspec
|
7
|
-
- vendor/bundle/**/*
|
8
|
-
- vendor/bundler/**/*
|
2
|
+
NewCops: enable
|
9
3
|
Metrics/BlockLength:
|
10
4
|
Exclude:
|
11
|
-
- spec/**/*
|
12
|
-
Metrics/LineLength:
|
13
|
-
Max: 80
|
14
|
-
IgnoredPatterns: ['(\A|\s+)#']
|
5
|
+
- spec/**/*_spec.rb
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Allow Enum values to be used in [Ransack](https://github.com/activerecord-hacker
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'ransack-enum', '~> 0.
|
10
|
+
gem 'ransack-enum', '~> 0.3'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -72,7 +72,7 @@ end
|
|
72
72
|
|
73
73
|
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.
|
74
74
|
|
75
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
75
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
76
76
|
|
77
77
|
## Contributing
|
78
78
|
|
data/lib/ransack/enum.rb
CHANGED
@@ -1,19 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/core_ext'
|
4
|
+
require 'ransack'
|
4
5
|
require 'ransack/enum/version'
|
5
|
-
require 'ransack/enum/adapters'
|
6
6
|
require 'ransack/enum/configuration'
|
7
|
+
require 'ransack/enum/adapters/active_record'
|
7
8
|
|
8
9
|
module Ransack
|
9
10
|
# Ransack::Enum
|
10
11
|
module Enum
|
11
12
|
extend Configuration
|
12
|
-
class Error < StandardError; end
|
13
|
-
# Your code goes here...
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
17
|
-
Ransack::Enum.configure do |config|
|
18
|
-
config.enabled = true
|
19
|
-
end
|
@@ -2,16 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'ransack/enum/adapters/active_record/base'
|
4
4
|
|
5
|
-
module Ransack
|
6
|
-
module Enum
|
7
|
-
module Adapters
|
8
|
-
# Ransack::Enum::Adapters::ActiveRecord
|
9
|
-
module ActiveRecord
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
5
|
ActiveSupport.on_load(:active_record) do
|
16
6
|
extend Ransack::Enum::Adapters::ActiveRecord::Base
|
17
7
|
end
|
@@ -10,33 +10,33 @@ module Ransack
|
|
10
10
|
# @param [Hash] definitions
|
11
11
|
# @return [Hash]
|
12
12
|
def enum(definitions)
|
13
|
-
|
14
|
-
|
15
|
-
definitions.each do |name, values|
|
16
|
-
enum_ransacker name, values
|
17
|
-
end
|
18
|
-
end
|
19
|
-
result
|
13
|
+
enum_ransacker(*definitions.to_a.first) if respond_to?(:ransacker)
|
14
|
+
super
|
20
15
|
end
|
21
16
|
|
22
|
-
|
17
|
+
private
|
18
|
+
|
23
19
|
# @param [Symbol] name
|
24
20
|
# @param [Hash] values
|
25
21
|
# @return [Hash]
|
26
22
|
def enum_ransacker(name, values)
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
converter = enum_ransack_value_converter(name.to_s, values)
|
24
|
+
ransacker name, formatter: lambda { |value|
|
25
|
+
value.is_a?(Array) ? value.map(&converter) : converter.call(value)
|
26
|
+
}
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
# @param [String] name
|
30
|
+
# @param [Hash] values
|
31
|
+
# @return [Proc]
|
32
|
+
def enum_ransack_value_converter(name, values)
|
33
|
+
lambda do |value|
|
34
|
+
val = values[value.to_sym]
|
35
|
+
return val if Ransack::Enum.enabled? && !val.nil?
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
}
|
37
|
+
Ransack::Nodes::Value.new(nil, value).cast(attribute_types[name]&.type)
|
38
|
+
end
|
38
39
|
end
|
39
|
-
# rubocop:enable Metrics/AbcSize
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -6,17 +6,21 @@ module Ransack
|
|
6
6
|
module Configuration
|
7
7
|
mattr_accessor :options
|
8
8
|
|
9
|
-
self.options = {
|
10
|
-
enabled: true
|
11
|
-
}
|
9
|
+
self.options = { enabled: true }
|
12
10
|
|
13
11
|
def configure
|
14
12
|
yield self
|
15
13
|
end
|
16
14
|
|
17
|
-
# @param [TrueClass, FalseClass]
|
18
|
-
|
19
|
-
|
15
|
+
# @param [TrueClass, FalseClass] enabled
|
16
|
+
# @return [TrueClass, FalseClass]
|
17
|
+
def enabled=(enabled)
|
18
|
+
options[:enabled] = enabled
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [TrueClass, FalseClass]
|
22
|
+
def enabled?
|
23
|
+
options[:enabled]
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
data/lib/ransack/enum/version.rb
CHANGED
data/ransack-enum.gemspec
CHANGED
@@ -1,36 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/ransack/enum/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
6
|
+
spec.name = 'ransack-enum'
|
7
7
|
spec.version = Ransack::Enum::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
8
|
+
spec.authors = %w[shoma07]
|
9
|
+
spec.email = %w[23730734+shoma07@users.noreply.github.com]
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.
|
15
|
-
spec.
|
11
|
+
spec.summary = 'Allow Enum values to be used in Ransack searches'
|
12
|
+
spec.description = 'Allow Enum values to be used in Ransack searches'
|
13
|
+
spec.homepage = 'https://github.com/shoma07/ransack-enum'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
16
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
|
20
20
|
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
22
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
25
|
end
|
26
|
-
spec.bindir =
|
26
|
+
spec.bindir = 'exe'
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
29
|
-
|
30
|
-
spec.add_dependency "ransack", "~> 2.0"
|
28
|
+
spec.require_paths = %w[lib]
|
31
29
|
|
32
|
-
spec.
|
33
|
-
spec.add_development_dependency "rake", ">= 12.3.3"
|
34
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
-
spec.add_development_dependency "sqlite3", "~> 1.4"
|
30
|
+
spec.add_dependency 'ransack', '~> 2.0'
|
36
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack-enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shoma07
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ransack
|
@@ -24,62 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '2.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '2.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 12.3.3
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 12.3.3
|
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: sqlite3
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.4'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.4'
|
83
27
|
description: Allow Enum values to be used in Ransack searches
|
84
28
|
email:
|
85
29
|
- 23730734+shoma07@users.noreply.github.com
|
@@ -88,8 +32,8 @@ extensions: []
|
|
88
32
|
extra_rdoc_files: []
|
89
33
|
files:
|
90
34
|
- ".gitignore"
|
35
|
+
- ".rspec"
|
91
36
|
- ".rubocop.yml"
|
92
|
-
- ".travis.yml"
|
93
37
|
- CHANGELOG.md
|
94
38
|
- Gemfile
|
95
39
|
- LICENSE.txt
|
@@ -98,7 +42,6 @@ files:
|
|
98
42
|
- bin/console
|
99
43
|
- bin/setup
|
100
44
|
- lib/ransack/enum.rb
|
101
|
-
- lib/ransack/enum/adapters.rb
|
102
45
|
- lib/ransack/enum/adapters/active_record.rb
|
103
46
|
- lib/ransack/enum/adapters/active_record/base.rb
|
104
47
|
- lib/ransack/enum/configuration.rb
|
@@ -110,7 +53,7 @@ licenses:
|
|
110
53
|
metadata:
|
111
54
|
homepage_uri: https://github.com/shoma07/ransack-enum
|
112
55
|
source_code_uri: https://github.com/shoma07/ransack-enum
|
113
|
-
changelog_uri: https://github.com/shoma07/ransack-enum/blob/v0.
|
56
|
+
changelog_uri: https://github.com/shoma07/ransack-enum/blob/v0.3.0/CHANGELOG.md
|
114
57
|
post_install_message:
|
115
58
|
rdoc_options: []
|
116
59
|
require_paths:
|
@@ -119,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
62
|
requirements:
|
120
63
|
- - ">="
|
121
64
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
65
|
+
version: 2.3.0
|
123
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
67
|
requirements:
|
125
68
|
- - ">="
|
data/.travis.yml
DELETED