missile_emitter 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +15 -19
- data/lib/missile_emitter/searchable.rb +12 -17
- data/lib/missile_emitter/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d225c1def8cf6ef48cce67f43d20d5951d301a0a40e357c346092262f9dddef
|
|
4
|
+
data.tar.gz: 980be4ba187119738d3bf629cfb1e09838e0b75e601faf3f6023172129bbac65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32138126bf5c2c0457d7944f44415312418b0140dc29a1f5383969a9701325e327f3bca03aab84158a181279296dcfd976fa8469e6f875c2aacddf56c77041c8
|
|
7
|
+
data.tar.gz: 1fbac0eca4068ba5d76d075d8a5443bde8f61392ace638e109daecad14c64970f5462d490a39d20603a9940cefa54bf10b2e7daf467231b2a83d81149a50ae74
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -110,26 +110,22 @@ module Searchable
|
|
|
110
110
|
(conditions[klass] ||= {}.with_indifferent_access)[key] = block
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
elsif column_names.include?(key)
|
|
127
|
-
relation.where key => value
|
|
128
|
-
else
|
|
129
|
-
relation
|
|
130
|
-
end
|
|
113
|
+
define_method :search do |hash|
|
|
114
|
+
hash.reduce all do |relation, (key, value)|
|
|
115
|
+
next relation if value.blank? # ignore empty value
|
|
116
|
+
|
|
117
|
+
if filter = conditions.fetch(self, {})[key]
|
|
118
|
+
relation.extending do
|
|
119
|
+
# Just for fun :) With Ruby >= 2.7 you can use _1 instead of _.
|
|
120
|
+
define_method(:_) { value }
|
|
121
|
+
end.instance_exec(value, &filter)
|
|
122
|
+
elsif column_names.include?(key.to_s)
|
|
123
|
+
relation.where key => value
|
|
124
|
+
else
|
|
125
|
+
relation
|
|
131
126
|
end
|
|
132
127
|
end
|
|
128
|
+
end
|
|
133
129
|
|
|
134
130
|
end
|
|
135
131
|
```
|
|
@@ -138,7 +134,7 @@ end
|
|
|
138
134
|
|
|
139
135
|
```ruby
|
|
140
136
|
class Person < ApplicationRecord
|
|
141
|
-
|
|
137
|
+
extend Searchable {
|
|
142
138
|
name_like { |keyword| where 'name like ?', "%#{keyword}%" }
|
|
143
139
|
older_than { where 'age >= ?', _ }
|
|
144
140
|
}
|
|
@@ -9,24 +9,19 @@ module MissileEmitter
|
|
|
9
9
|
(conditions[klass] ||= {}.with_indifferent_access)[key] = block
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
define_method :search do |hash|
|
|
13
|
+
hash.reduce all do |relation, (key, value)|
|
|
14
|
+
next relation if value.blank? # ignore empty value
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
define_method(:_) { value }
|
|
24
|
-
end.instance_exec(value, &filter)
|
|
25
|
-
elsif column_names.include?(key.to_s)
|
|
26
|
-
relation.where key => value
|
|
27
|
-
else
|
|
28
|
-
relation
|
|
29
|
-
end
|
|
16
|
+
if filter = conditions.fetch(self, {})[key]
|
|
17
|
+
relation.extending do
|
|
18
|
+
# Just for fun :) With Ruby >= 2.7 you can use _1 instead of _.
|
|
19
|
+
define_method(:_) { value }
|
|
20
|
+
end.instance_exec(value, &filter)
|
|
21
|
+
elsif column_names.include?(key.to_s)
|
|
22
|
+
relation.where key => value
|
|
23
|
+
else
|
|
24
|
+
relation
|
|
30
25
|
end
|
|
31
26
|
end
|
|
32
27
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: missile_emitter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jerry Chen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-01-
|
|
11
|
+
date: 2020-01-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
115
115
|
- !ruby/object:Gem::Version
|
|
116
116
|
version: '0'
|
|
117
117
|
requirements: []
|
|
118
|
-
rubygems_version: 3.
|
|
118
|
+
rubygems_version: 3.1.2
|
|
119
119
|
signing_key:
|
|
120
120
|
specification_version: 4
|
|
121
121
|
summary: Ruby元编程辅助工具
|