wharel 0.3.0 → 0.4.0
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/CHANGELOG.md +10 -3
- data/README.md +7 -3
- data/lib/wharel.rb +8 -4
- data/lib/wharel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c803c1e0aa9c250d629af479b9ccbc85c615654d5b3cd3ea1090a519f3a883
|
4
|
+
data.tar.gz: 183364f83c7f226c02ab2d2498dbe0caa429cb684c2c1ca9180d689e33245832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9890716f4e44c82a5e8df2dea4d29987dc7ae21ad1ea20802ae53ccaf47b1be453309ac221335d1433677ba8b3e2366351cc721a7689e1b339741114ac38991
|
7
|
+
data.tar.gz: 3341d125908a27b82f70bbbc7626adb4621c37d9bf69fb272a93b32e434772fb9e8132284d79e0730af3c61a0b9f057353b994a484264311f304009a414af523
|
data/CHANGELOG.md
CHANGED
@@ -1,19 +1,26 @@
|
|
1
1
|
# Wharel Changelog
|
2
2
|
|
3
|
+
## 0.4
|
4
|
+
|
5
|
+
### 0.4.0 (November 2, 2019)
|
6
|
+
|
7
|
+
- Add support for `group`, `having`, `pluck` and `or`
|
8
|
+
([#8](https://github.com/shioyama/wharel/pull/8))
|
9
|
+
|
3
10
|
## 0.3
|
4
11
|
|
5
|
-
### 0.3.0
|
12
|
+
### 0.3.0 (November 1, 2019)
|
6
13
|
|
7
14
|
- Add support for `order` ([#2](https://github.com/shioyama/wharel/pull/7))
|
8
15
|
|
9
16
|
## 0.2
|
10
17
|
|
11
|
-
### 0.2.0
|
18
|
+
### 0.2.0 (May 25, 2018)
|
12
19
|
|
13
20
|
- Add support for `where.not` ([#1](https://github.com/shioyama/wharel/pull/1))
|
14
21
|
|
15
22
|
## 0.1
|
16
23
|
|
17
|
-
### 0.1.0
|
24
|
+
### 0.1.0 (May 25, 2018)
|
18
25
|
|
19
26
|
- Basic support for `where` with blocks.
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Wharel
|
2
2
|
|
3
|
+
[][gem]
|
3
4
|
[][travis]
|
4
5
|
|
6
|
+
[gem]: https://rubygems.org/gems/wharel
|
5
7
|
[travis]: https://travis-ci.org/shioyama/wharel
|
6
8
|
|
7
9
|
Wharel helps you write concise Arel queries with ActiveRecord using Virtual
|
@@ -26,7 +28,7 @@ post](https://dejimata.com/2018/5/30/arel-with-wharel).
|
|
26
28
|
Add this line to your application's Gemfile:
|
27
29
|
|
28
30
|
```ruby
|
29
|
-
gem 'wharel', '~> 0.
|
31
|
+
gem 'wharel', '~> 0.4.0'
|
30
32
|
```
|
31
33
|
|
32
34
|
And then execute:
|
@@ -68,18 +70,20 @@ Post.where { title.matches("foo").and(content.matches("bar")) }
|
|
68
70
|
Wharel will map `title` and `content` in the block to the appropriate Arel
|
69
71
|
attribute for the column.
|
70
72
|
|
71
|
-
|
73
|
+
Wharel also supports most other query methods, e.g. `not`:
|
72
74
|
|
73
75
|
```ruby
|
74
76
|
Post.where.not { title.eq("foo") }
|
75
77
|
```
|
76
78
|
|
77
|
-
... and
|
79
|
+
... and `order`:
|
78
80
|
|
79
81
|
```ruby
|
80
82
|
Post.order { title.lower }
|
81
83
|
```
|
82
84
|
|
85
|
+
Wharel also supports `having`, `pluck`, `group` and `or` in the same way.
|
86
|
+
|
83
87
|
Now suppose we have another model `Comment` with a column `content`, and a
|
84
88
|
`Post` `has_many :comments`:
|
85
89
|
|
data/lib/wharel.rb
CHANGED
@@ -3,12 +3,16 @@ require "active_record"
|
|
3
3
|
|
4
4
|
module Wharel
|
5
5
|
module QueryMethods
|
6
|
-
|
7
|
-
|
6
|
+
%w[where order having pluck group].each do |method_name|
|
7
|
+
module_eval <<-EOM, __FILE__, __LINE__ + 1
|
8
|
+
def #{method_name}(*, &block)
|
9
|
+
block_given? ? super(VirtualRow.build_query(self, &block)) : super
|
10
|
+
end
|
11
|
+
EOM
|
8
12
|
end
|
9
13
|
|
10
|
-
def
|
11
|
-
block_given? ? super(VirtualRow.build_query(self, &block)) : super
|
14
|
+
def or(*, &block)
|
15
|
+
block_given? ? super(model.where(VirtualRow.build_query(self, &block))) : super
|
12
16
|
end
|
13
17
|
|
14
18
|
module WhereChain
|
data/lib/wharel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wharel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Salzberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|