rokaki 0.4.0 → 0.4.1

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: 0fd44ddd6bbfce39a8417111397fda97131f893d9e502b9a43c1068a18fae5ba
4
- data.tar.gz: b17ce9c86ae2a7ed95a358662c48fde64e29c6d647a4d3e38f7d13ac6275f201
3
+ metadata.gz: e5d32983f1791295aadabcc64fafca2e7cda63e679b0e37fcf38fc41085679e5
4
+ data.tar.gz: f1125b9db501745d1d3cad0da31b378f90fd1e5b44b2cdf0e8a2429eea91dea2
5
5
  SHA512:
6
- metadata.gz: 8574514a686795b089997a792cbf188ac82ed8751a94d5a0469d6ed92cf7860dd31d13762887972c6546e7e24f5427dfdd52f1c907c95e82de8f4509bec3d616
7
- data.tar.gz: a38042fff170ed676be0fd9585b2fc9f1ce7ed9691fead44c9744724d6dfe94c65ed8ab005feaaaf7555268f653ab1906aa2765012036698cc8b4a43bb49c0e8
6
+ metadata.gz: fcac7ca5e906933335255fb59c63b2e8114a864cd8a6c9f2868c9e64a25566c6c00d9439c01dc372b123443e953cd45930ceb93bc80cd43dc3f6da48ad029f83
7
+ data.tar.gz: c9f3742c1ec502b04453ab373eff82646c67b8d134981b67838666f185d5b6d36fefc0371ee386d60fda6a17f6e2e90d52a17e6de5963bb501d365a8e4eb4c24
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rokaki (0.3.0)
4
+ rokaki (0.4.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Rokaki
2
+ [![Gem Version](https://badge.fury.io/rb/rokaki.svg)](https://badge.fury.io/rb/rokaki)
2
3
 
3
4
  This gem was born out of a desire to dry up filtering services in Rails or any ruby app that uses the concept of `filters`.
4
5
 
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rokaki
4
- module FilterModel
5
- module Like
6
- def self.included(base)
7
- base.extend(ClassMethods)
8
- end
9
-
10
- module ClassMethods
11
- def like(args)
12
- raise ArgumentError, 'argument mush be a hash' unless args.is_a? Hash
13
- @_like_semantics = (@_like_semantics || {}).merge(args)
14
- end
15
-
16
- def _chain_filter_like_type(key)
17
- filter = "#{filter_key_prefix}#{key}"
18
-
19
- query = "@model.where(\"#{key} LIKE :query\", "
20
- if mode == :circumfix
21
- query += "query: \"%\#{#{filter}}%\")"
22
- end
23
- if mode == :infix
24
- query += "query: \"%\#{#{filter}}\")"
25
- end
26
- if mode == :suffix
27
- query += "query: \"\#{#{filter}}%\")"
28
- end
29
- "#{query};"
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -113,39 +113,11 @@ module Rokaki
113
113
 
114
114
  def like(args)
115
115
  raise ArgumentError, 'argument mush be a hash' unless args.is_a? Hash
116
-
117
- like_keys = {base: []}
118
- args.keys.each do |key|
119
- map_like_keys(like_keys, args, key)
120
- end
121
-
122
116
  @_like_semantics = (@_like_semantics || {}).merge(args)
123
117
 
124
- base_keys = like_keys.delete(:base)
125
- key_results = base_keys << like_keys
118
+ key_builder = LikeKeys.new(args)
126
119
 
127
- filters(*key_results)
128
- end
129
-
130
- def map_like_keys(key_result, base_object, key)
131
- sub_object = base_object[key]
132
- if sub_object.is_a? Hash
133
- sub_object.keys.each do |sub_key|
134
- sub_object_value = sub_object[sub_key]
135
- if sub_object_value.is_a? Symbol
136
- if key_result[key].is_a? Array
137
- key_result[key] << sub_key
138
- else
139
- key_result[key] = [sub_key]
140
- end
141
- elsif sub_object_value.is_a? Hash
142
- map_like_keys(key_result, sub_object, sub_key)
143
- end
144
- end
145
- elsif sub_object.is_a? Symbol
146
- key_result[:base] << key
147
- end
148
- key_result
120
+ filters(*key_builder.call)
149
121
  end
150
122
 
151
123
  def deep_chain(keys, value)
@@ -1,3 +1,3 @@
1
1
  module Rokaki
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/rokaki.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rokaki/version'
4
4
  require 'rokaki/filterable'
5
5
  require 'rokaki/filter_model'
6
+ require 'rokaki/filter_model/like_keys'
6
7
 
7
8
  module Rokaki
8
9
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rokaki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Martin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-10 00:00:00.000000000 Z
11
+ date: 2019-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler