wharel 0.1.0 → 0.2.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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +12 -2
- data/lib/wharel.rb +7 -0
- data/lib/wharel/version.rb +1 -1
- metadata +1 -1
- metadata.gz.sig +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6ddbdc7852c67834cd3bfcd0a5fd12e46fdf6679a81c10c33f016d0ad46e902
|
4
|
+
data.tar.gz: f2365f7188bc6ed17e3938027efe39e5c7daf16bc00847de9dbdd8c62502f9ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29093610ff9d675b74417951434e24105e83d89bfdf9c2a2394d6069b905b0b4aefc0614357f9c8cc6b235dcbae5968244f38ac1c16438df6e497c8e3e0e344e
|
7
|
+
data.tar.gz: 517eabee061ded8ab3bd39b258402e87cc1ea61c6bc51f18d87dd64aa3090d52f4a18ccb762d704c1d9f1ad6cd3ff90185bf3c37321b54365afdc182fc4ee527
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Wharel
|
2
2
|
|
3
|
+
[][travis]
|
4
|
+
|
5
|
+
[travis]: https://travis-ci.org/shioyama/wharel
|
6
|
+
|
3
7
|
Wharel helps you write concise Arel queries with ActiveRecord using Virtual
|
4
8
|
Rows inspired by
|
5
9
|
[Sequel](http://sequel.jeremyevans.net/rdoc/files/doc/virtual_rows_rdoc.html).
|
@@ -8,7 +12,7 @@ Although similar in spirit to gems like
|
|
8
12
|
[Squeel](https://github.com/activerecord-hackery/squeel) and
|
9
13
|
[BabySqueel](https://github.com/rzane/baby_squeel), which provide sophisticated
|
10
14
|
block-based interfaces for querying with Arel, Wharel is much much smaller. In
|
11
|
-
fact, the core of the gem is only [
|
15
|
+
fact, the core of the gem is only [30 lines
|
12
16
|
long](https://github.com/shioyama/wharel/blob/master/lib/wharel.rb)! It uses a
|
13
17
|
single `BasicObject` as a [clean
|
14
18
|
room](https://www.sethvargo.com/the-cleanroom-pattern/) to evaluate
|
@@ -19,7 +23,7 @@ the query block. That's really all there is to it.
|
|
19
23
|
Add this line to your application's Gemfile:
|
20
24
|
|
21
25
|
```ruby
|
22
|
-
gem 'wharel'
|
26
|
+
gem 'wharel', '~> 0.2.0'
|
23
27
|
```
|
24
28
|
|
25
29
|
And then execute:
|
@@ -61,6 +65,12 @@ Post.where { title.matches("foo").and(content.matches("bar")) }
|
|
61
65
|
Wharel will map `title` and `content` in the block to the appropriate Arel
|
62
66
|
attribute for the column.
|
63
67
|
|
68
|
+
Works with `where.not` too:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
Post.where.not { title.eq("foo") }
|
72
|
+
```
|
73
|
+
|
64
74
|
Now suppose we have another model `Comment` with a column `content`, and a
|
65
75
|
`Post` `has_many :comments`:
|
66
76
|
|
data/lib/wharel.rb
CHANGED
@@ -6,6 +6,12 @@ module Wharel
|
|
6
6
|
def where(opts = :chain, *rest, &block)
|
7
7
|
block_given? ? super(VirtualRow.build_query(self, &block)) : super
|
8
8
|
end
|
9
|
+
|
10
|
+
module WhereChain
|
11
|
+
def not(*args, &block)
|
12
|
+
block_given? ? super(VirtualRow.build_query(@scope, &block)) : super
|
13
|
+
end
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
class VirtualRow < BasicObject
|
@@ -30,3 +36,4 @@ end
|
|
30
36
|
# Monkey-patch ActiveRecord. Should make this optional.
|
31
37
|
::ActiveRecord::Base.singleton_class.prepend ::Wharel::QueryMethods
|
32
38
|
::ActiveRecord::Relation.prepend ::Wharel::QueryMethods
|
39
|
+
::ActiveRecord::QueryMethods::WhereChain.prepend ::Wharel::QueryMethods::WhereChain
|
data/lib/wharel/version.rb
CHANGED
metadata
CHANGED
metadata.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
�����w�-'��=aNAh閲������p�s�pYӬT�I��>4y9t�����̊<�t(Y��Ǐ�o8XEA���f��8N���W���ڙ�� �#c�<Ks���e�U��{3N�,�jg�m�g�^$:��}�0�ϋ���Ȳ܇PL =V˯�v0jU�!`6?֗�ͽ��6;�?6����)�t0ٵ<�8TE��+��h~1:�\�L+�h�|�Tb�$;��6��s�eP�Lkz�
|