wharel 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +16 -2
- data/README.md +68 -7
- data/lib/wharel/version.rb +1 -1
- metadata +29 -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: 6f1a415500f1ace6b7dd7ef92e229fd7d4586bb540c205cc70bddf0658b76484
|
4
|
+
data.tar.gz: 9f0368d29226dc719e46a9e6ec33e2499f2d9b1926c76b16654d2003a8270b78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '04528bf9b9fd6d710c779c477e180f496738b8a390ceea7ce9f5c315a9ace364bad3177dfe3120e36df2fdeb0d384d5e01e95a2706b3b985ab48d3a9eed9c393'
|
7
|
+
data.tar.gz: 922b8917d0c62596b2c693efcda21c77cb84d9fa599c5cc75a232dce82f11beda1939199abafdacbdddbacfd8d7f874d18a0928d6e906aa4db49097d0e22e98d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wharel (0.1
|
5
|
-
activerecord (~> 5.
|
4
|
+
wharel (0.0.1)
|
5
|
+
activerecord (~> 5.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -19,11 +19,21 @@ GEM
|
|
19
19
|
minitest (~> 5.1)
|
20
20
|
tzinfo (~> 1.1)
|
21
21
|
arel (9.0.0)
|
22
|
+
byebug (10.0.2)
|
23
|
+
coderay (1.1.2)
|
22
24
|
concurrent-ruby (1.0.5)
|
25
|
+
database_cleaner (1.7.0)
|
23
26
|
diff-lcs (1.3)
|
24
27
|
i18n (1.0.1)
|
25
28
|
concurrent-ruby (~> 1.0)
|
29
|
+
method_source (0.9.0)
|
26
30
|
minitest (5.11.3)
|
31
|
+
pry (0.11.3)
|
32
|
+
coderay (~> 1.1.0)
|
33
|
+
method_source (~> 0.9.0)
|
34
|
+
pry-byebug (3.6.0)
|
35
|
+
byebug (~> 10.0)
|
36
|
+
pry (~> 0.10)
|
27
37
|
rake (10.5.0)
|
28
38
|
rspec (3.7.0)
|
29
39
|
rspec-core (~> 3.7.0)
|
@@ -38,6 +48,7 @@ GEM
|
|
38
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
49
|
rspec-support (~> 3.7.0)
|
40
50
|
rspec-support (3.7.1)
|
51
|
+
sqlite3 (1.3.13)
|
41
52
|
thread_safe (0.3.6)
|
42
53
|
tzinfo (1.2.5)
|
43
54
|
thread_safe (~> 0.1)
|
@@ -47,8 +58,11 @@ PLATFORMS
|
|
47
58
|
|
48
59
|
DEPENDENCIES
|
49
60
|
bundler (~> 1.16)
|
61
|
+
database_cleaner
|
62
|
+
pry-byebug
|
50
63
|
rake (~> 10.0)
|
51
64
|
rspec (~> 3.0)
|
65
|
+
sqlite3
|
52
66
|
wharel!
|
53
67
|
|
54
68
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
# Wharel
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
Wharel helps you write concise Arel queries with ActiveRecord using Virtual
|
4
|
+
Rows inspired by
|
5
|
+
[Sequel](http://sequel.jeremyevans.net/rdoc/files/doc/virtual_rows_rdoc.html).
|
6
|
+
|
7
|
+
Although similar in spirit to gems like
|
8
|
+
[Squeel](https://github.com/activerecord-hackery/squeel) and
|
9
|
+
[BabySqueel](https://github.com/rzane/baby_squeel), which provide sophisticated
|
10
|
+
block-based interfaces for querying with Arel, Wharel is much much smaller. In
|
11
|
+
fact, the core of the gem is only [25 lines
|
12
|
+
long](https://github.com/shioyama/wharel/blob/master/lib/wharel.rb)! It uses a
|
13
|
+
single `BasicObject` as a [clean
|
14
|
+
room](https://www.sethvargo.com/the-cleanroom-pattern/) to evaluate
|
15
|
+
the query block. That's really all there is to it.
|
6
16
|
|
7
17
|
## Installation
|
8
18
|
|
@@ -22,13 +32,64 @@ Or install it yourself as:
|
|
22
32
|
|
23
33
|
## Usage
|
24
34
|
|
25
|
-
|
35
|
+
Suppose we have a model `Post`:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Post < ApplicationRecord
|
39
|
+
has_many :comments
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
And let's assume our `Post` has columns `title` and `content`.
|
44
|
+
|
45
|
+
Now, if we wanted to find all the posts with a title which matched the string
|
46
|
+
"foo" and content which matched the string "bar", we'd have to resort to
|
47
|
+
something like this:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
title = Post.arel_table[:title]
|
51
|
+
content = Post.arel_table[:content]
|
52
|
+
Post.where(title.matches("foo").and(content.matches("bar")))
|
53
|
+
```
|
54
|
+
|
55
|
+
With Wharel, you can drop the boilerplate and just use a block:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Post.where { title.matches("foo").and(content.matches("bar")) }
|
59
|
+
```
|
26
60
|
|
27
|
-
|
61
|
+
Wharel will map `title` and `content` in the block to the appropriate Arel
|
62
|
+
attribute for the column.
|
28
63
|
|
29
|
-
|
64
|
+
Now suppose we have another model `Comment` with a column `content`, and a
|
65
|
+
`Post` `has_many :comments`:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class Post < ApplicationRecord
|
69
|
+
has_many :comments
|
70
|
+
end
|
71
|
+
|
72
|
+
class Comment < ApplicationRecord
|
73
|
+
belongs_to :post
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
Now we want to find all comments which match the title of the comment's post.
|
78
|
+
With standard Arel, you could do this with:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
posts = Post.arel_table
|
82
|
+
comments = Comment.arel_table
|
83
|
+
Comment.joins(:post).where(comments[:content].matches(posts[:title]))
|
84
|
+
```
|
85
|
+
|
86
|
+
Using Wharel, you can pass an argument to blocks to handle this case:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
Comment.joins(:post).where { |c| Post.where { |p| c.content.matches(p.title) } }
|
90
|
+
```
|
30
91
|
|
31
|
-
|
92
|
+
Much better!
|
32
93
|
|
33
94
|
## Contributing
|
34
95
|
|
data/lib/wharel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wharel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Salzberg
|
@@ -88,6 +88,34 @@ dependencies:
|
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '3.0'
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: sqlite3
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: database_cleaner
|
107
|
+
requirement: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
91
119
|
description: Use arel predicates directly from where.
|
92
120
|
email:
|
93
121
|
- chris@dejimata.com
|
metadata.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
0G���9���u�����R�Y�?O5����ti����X�L����((d�>��XX3����@�?;�j�X�Ĭ�}#���2�����,;�����vB���囘�;G���+�
|