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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00cd2885a78feb0ef6e8bfff5430d48d60e0b7315ae794a4861114766d4ca598
4
- data.tar.gz: 2873e16ea17ea641655ec8902dc5dc9027ae905e8d162448843b38ec3252ad7c
3
+ metadata.gz: e7d29a6d9f1aeb5b49f746c0c16e41b4690ebe4070f90fa5186572927b8ac2ee
4
+ data.tar.gz: a2358d2de52e1297aa65ef24c8a3a4529ff484e657716b7777d670483f9608b9
5
5
  SHA512:
6
- metadata.gz: 057fbba06a62a73c8598bdbd4cf716f437630cc7f5b09df1e02d039c29c6a00bdc6e699bbb628fd5f0b3ca9a43a227df3cac9b728445623329374ac605d85e6f
7
- data.tar.gz: cdfbcd0ec45acba4694f7de9fbae10158e18a98dcaf2f6713e8a5eb8568aa31a638f2d1e134bfb1813263ed67e3adab6c1392a3fd10486598b382ae94b7b5fcc
6
+ metadata.gz: 64372e91b20d14ccf56ee0567f2aecc9940e2d39c83ca505173a49cea70dc6083fdc6586882c9608e2225d55ac46e8c9009e9e689bb2c5ec6ced8d9934cf7ea1
7
+ data.tar.gz: a3d1790361f9886debedc89d336cab5fea1eb4e17a4faa216c76262dcdc32535666b213bf1b1a60e62db9e53635b47f08a6f7977a1324275a8306767991d6708
data/.gitignore CHANGED
@@ -9,7 +9,6 @@
9
9
  /vendor
10
10
  .DS_Store
11
11
  Gemfile.lock
12
- .rspec
13
12
 
14
13
  # rspec failure tracking
15
14
  .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -1,14 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6.5
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
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.3.0 / 2020-09-28
4
+ ### New features
5
+ - Support boolean enum value
6
+ ### Hotfix
7
+ - Change other than #enum to private
8
+
3
9
  ## 0.2.1 / 2020-03-17
4
10
  ### Hotfix
5
11
  - Generating an automated security update (rake)
data/Gemfile CHANGED
@@ -1,4 +1,10 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in ransack-enum.gemspec
4
6
  gemspec
7
+
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'sqlite3'
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.2'
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`. 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).
75
+ To install this gem onto your local machine, run `bundle exec rake install`.
76
76
 
77
77
  ## Contributing
78
78
 
@@ -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
- result = super(definitions)
14
- if respond_to?(:ransacker)
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
- # rubocop:disable Metrics/AbcSize
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
- lmd = lambda do |val|
28
- v = values[val.to_sym]
29
- return v if Ransack::Enum.options[:enabled] && v
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
- type = attribute_types[name.to_s]&.type
32
- Ransack::Nodes::Value.new(nil, val).cast(type)
33
- end
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
- ransacker name.to_sym, formatter: proc { |val|
36
- val.is_a?(Array) ? val.map { |v| lmd.call(v) } : lmd.call(val)
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] boolean
18
- def enabled=(boolean)
19
- options[:enabled] = boolean
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ransack
4
4
  module Enum
5
- VERSION = '0.2.1'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -1,36 +1,31 @@
1
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "ransack/enum/version"
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 = "ransack-enum"
6
+ spec.name = 'ransack-enum'
7
7
  spec.version = Ransack::Enum::VERSION
8
- spec.authors = ["shoma07"]
9
- spec.email = ["23730734+shoma07@users.noreply.github.com"]
8
+ spec.authors = %w[shoma07]
9
+ spec.email = %w[23730734+shoma07@users.noreply.github.com]
10
10
 
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.required_ruby_version = ">= 2.3"
15
- spec.license = "MIT"
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["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = "https://github.com/shoma07/ransack-enum/blob/v#{spec.version}/CHANGELOG.md"
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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 = "exe"
26
+ spec.bindir = 'exe'
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
29
-
30
- spec.add_dependency "ransack", "~> 2.0"
28
+ spec.require_paths = %w[lib]
31
29
 
32
- spec.add_development_dependency "bundler", "~> 2.0"
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.2.1
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-03-16 00:00:00.000000000 Z
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.2.1/CHANGELOG.md
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: '2.3'
65
+ version: 2.3.0
123
66
  required_rubygems_version: !ruby/object:Gem::Requirement
124
67
  requirements:
125
68
  - - ">="
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.5
7
- before_install: gem install bundler -v 2.0.2
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ransack/enum/adapters/active_record'
4
-
5
- module Ransack
6
- module Enum
7
- # Ransack::Enum::Adapters
8
- module Adapters
9
- end
10
- end
11
- end