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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cc08c38afc3848972e34af95c8251bf82c8b2cdf753a97a72b6114413cb8c95
4
- data.tar.gz: 49fddc078c65170e7f9b67b81efde57f7de81235d6793a7d410cb6aae6bbc824
3
+ metadata.gz: 6f1a415500f1ace6b7dd7ef92e229fd7d4586bb540c205cc70bddf0658b76484
4
+ data.tar.gz: 9f0368d29226dc719e46a9e6ec33e2499f2d9b1926c76b16654d2003a8270b78
5
5
  SHA512:
6
- metadata.gz: abe42c838ceb0c5d785501fe719ca702e5f9a973fc6b84af176775123f0bdd47c7a2101ecd39d4317202f47ee1af8101e110ed9294b5f73fc9371f9c7a2280e1
7
- data.tar.gz: dead1e758bd94c11b02a3be8ff623a13e8d058610b9f2dd1fa88d8063dfbdf219ada4814ce21be1c0bd444366f09c79240e0e3e849196d69d2034a176a4959de
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
@@ -4,3 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in wharel.gemspec
6
6
  gemspec
7
+
8
+ gem 'pry-byebug'
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wharel (0.1.0)
5
- activerecord (~> 5.2)
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wharel`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
- ## Development
61
+ Wharel will map `title` and `content` in the block to the appropriate Arel
62
+ attribute for the column.
28
63
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
92
+ Much better!
32
93
 
33
94
  ## Contributing
34
95
 
@@ -1,3 +1,3 @@
1
1
  module Wharel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.1
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
- $ˢ����03S%fN,� =̕���x�X�C�{��(�S�c����g�=���h�ϵ��b��.�D9
1
+ 0G���9���u�����RY�?O5����ti����X�L����((d�>��XX3����@�?;�jX�Ĭ�}#���2�����,;�����vB���囘�;G���+�