baby_squeel 0.3.0 → 0.3.1

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
  SHA1:
3
- metadata.gz: 7011dd272658bb35f29c2fee9bef07432c6fd6b8
4
- data.tar.gz: 987fcf1f4682154eefb19e8aeb9e2671f48d04ea
3
+ metadata.gz: d7d31d8ac2c6564c5116b4fcfb2175c7747e1689
4
+ data.tar.gz: a1882420d085c5d2e071434ae8da6d28951ad3f9
5
5
  SHA512:
6
- metadata.gz: 9f1b3d6e1f178ab428df6b1c23d7672ba2c53fa0f14814cf72c60c294e1236ba01240f875a3c5bbdde21d25976da72403786325f274bcd28020b0dfbaf474c41
7
- data.tar.gz: 72efcf684fe78d5918914384d9f315b173adafa53af5044ce053c4b8ddb11a86067121c87997efd4254550d01064b825c68d5378b327e424dd6763bdc22e0c57
6
+ metadata.gz: 3fdc066c0f04ebe17744c95cbc4499a492c993ca23d06fc6b11b41077d7d2a45591504f7a831b4fdf1e21aa16c640b6847a1bbf58e7fc3b1b232e0366209b0d9
7
+ data.tar.gz: dac5d32acfb013e580aa4e51433a6b1e2bafe17288001feb09295f1da2b26e93a61486598c8884707e687ee591c024ac7ad82091b5a1833ed239f2ee009cfb42
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Nothing yet.
4
4
 
5
+ ## [0.3.1] - 2016-08-02
6
+ ### Added
7
+ - Ported backticks and #my from Squeel
8
+
9
+ ### Changed
10
+ - DSL#sql now returns a node wrapped in a BabySqueel proxy.
11
+
5
12
  ## [0.3.0] - 2016-06-26
6
13
  ### Added
7
14
  - Added Squeel compatibility mode that allows `select`, `order`, `joins`, `group`, `where`, and `having` to accept DSL blocks.
@@ -45,7 +52,8 @@ Nothing yet.
45
52
  ### Added
46
53
  - Initial support for selects, orders, wheres, and joins.
47
54
 
48
- [Unreleased]: https://github.com/rzane/baby_squeel/compare/v0.3.0...HEAD
55
+ [Unreleased]: https://github.com/rzane/baby_squeel/compare/v0.3.1...HEAD
56
+ [0.3.1]: https://github.com/rzane/baby_squeel/compare/v0.3.0...v0.3.1
49
57
  [0.3.0]: https://github.com/rzane/baby_squeel/compare/v0.2.2...v0.3.0
50
58
  [0.2.2]: https://github.com/rzane/baby_squeel/compare/v0.2.1...v0.2.2
51
59
  [0.2.1]: https://github.com/rzane/baby_squeel/compare/v0.2.0...v0.2.1
data/README.md CHANGED
@@ -228,6 +228,19 @@ Post.joining {
228
228
  }
229
229
  ```
230
230
 
231
+ ##### Helpers
232
+
233
+ ```ruby
234
+ # SQL Literals
235
+ Post.select('1 as one').ordering { sql('one').desc }
236
+
237
+ # Quoting
238
+ Post.selecting { title.op('||', quoted('diddly')) }
239
+
240
+ # Functions
241
+ Post.select { func('coalesce', id, 1) }
242
+ ```
243
+
231
244
  ## Sifters
232
245
 
233
246
  Sifters are like little snippets of conditions that can take arguments.
@@ -1,10 +1,27 @@
1
1
  module BabySqueel
2
2
  module Compat
3
3
  def self.enable!
4
+ BabySqueel::DSL.prepend BabySqueel::Compat::DSL
4
5
  ::ActiveRecord::Base.singleton_class.prepend QueryMethods
5
6
  ::ActiveRecord::Relation.prepend QueryMethods
6
7
  end
7
8
 
9
+ module DSL
10
+ def `(str)
11
+ sql(str)
12
+ end
13
+
14
+ def my(&block)
15
+ @caller.instance_eval(&block)
16
+ end
17
+
18
+ # Remember the original binding of the block
19
+ def evaluate(&block)
20
+ @caller = block.binding.eval('self')
21
+ super
22
+ end
23
+ end
24
+
8
25
  module QueryMethods
9
26
  def joins(*args, &block)
10
27
  if block_given? && args.empty?
@@ -56,7 +73,7 @@ module BabySqueel
56
73
 
57
74
  def where(*args, &block)
58
75
  if block_given? && args.empty?
59
- super DSL.evaluate(self, &block)
76
+ where.has(&block)
60
77
  else
61
78
  super
62
79
  end
@@ -50,7 +50,7 @@ module BabySqueel
50
50
 
51
51
  # See Arel::sql
52
52
  def sql(value)
53
- ::Arel.sql value
53
+ Nodes.wrap ::Arel.sql(value)
54
54
  end
55
55
 
56
56
  # Quotes a string and marks it as SQL
@@ -1,3 +1,3 @@
1
1
  module BabySqueel
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baby_squeel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-26 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.5.1
126
+ rubygems_version: 2.4.8
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: A tiny squeel implementation without all of the evil.