baby_squeel 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/README.md +78 -5
- data/baby_squeel.gemspec +1 -4
- data/lib/baby_squeel.rb +1 -0
- data/lib/baby_squeel/active_record.rb +24 -15
- data/lib/baby_squeel/dsl.rb +39 -5
- data/lib/baby_squeel/join_dependency.rb +26 -7
- data/lib/baby_squeel/nodes.rb +13 -4
- data/lib/baby_squeel/operators.rb +1 -1
- data/lib/baby_squeel/table.rb +23 -17
- data/lib/baby_squeel/version.rb +1 -1
- metadata +5 -10
- data/.gitignore +0 -9
- data/.rspec +0 -2
- data/.travis.yml +0 -19
- data/Gemfile +0 -17
- data/Rakefile +0 -41
- data/bin/console +0 -25
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc084f58970dcb50513671717f743e024a391355
|
4
|
+
data.tar.gz: 1a4430236093f7554273c2a4357e0ad81879fe2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc821c6eaca9be86e6559a2c354b47125a8a6c549e6b1b4064bc6354baa7ff6ecf186ebe66141b05681f77656834b787dbce705786f5e785e67fd4df3b859df1
|
7
|
+
data.tar.gz: d9428e48fd5ce4b0d21b88c253616de212e7bda084e5af79888439f2f97180593757cb0a0fdf0efbdd3f952e97e9193412b201557580967802065cbf66b65d93
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
Nothing yet!
|
4
|
+
|
5
|
+
## [0.2.2] - 2015-03-30
|
6
|
+
### Added
|
7
|
+
- Support for `group` (`grouping`) and `having` (`when_having`).
|
8
|
+
- Support for sifters.
|
9
|
+
- Added `quoted` and `sql` helpers for quoting strings and SQL literals.
|
10
|
+
- More descriptive error messages when a column or association is not found.
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- `Arel::Nodes::Grouping` does not include `Arel::Math`, so operations like `(id + 5) + 3` would fail unexpectedly.
|
14
|
+
- Fix missing bind values When joining through associations with default scope.
|
15
|
+
- Removed `ActiveRecord::VERSION` specific handling of the `WhereChain`.
|
16
|
+
|
17
|
+
## [0.2.1] - 2015-03-27
|
18
|
+
### Added
|
19
|
+
- Support for subqueries.
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
- Some Arel nodes did not have access to `as` expressions.
|
23
|
+
|
24
|
+
## [0.2.0] - 2015-03-25
|
25
|
+
### Added
|
26
|
+
- References to aliased joins in a `select`, `where`, or `order` expression now use the aliased table name.
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
- Rely on `ActiveRecord::Relation#join_sources` for the implicit construction of join nodes, rather than using the `ActiveRecord::Associations::JoinDependency` directly.
|
30
|
+
|
31
|
+
### Fixed
|
32
|
+
|
33
|
+
- Associations referencing the same table weren't being aliased.
|
34
|
+
|
35
|
+
## [0.1.0] - 2015-03-16
|
36
|
+
### Added
|
37
|
+
- Initial support for selects, orders, wheres, and joins.
|
38
|
+
|
39
|
+
[Unreleased]: https://github.com/rzane/baby_squeel/compare/v0.2.2...HEAD
|
40
|
+
[0.2.1]: https://github.com/rzane/baby_squeel/compare/v0.2.1...v0.2.2
|
41
|
+
[0.2.1]: https://github.com/rzane/baby_squeel/compare/v0.2.0...v0.2.1
|
42
|
+
[0.2.0]: https://github.com/rzane/baby_squeel/compare/v0.1.0...v0.2.0
|
data/README.md
CHANGED
@@ -28,6 +28,34 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
$ gem install baby_squeel
|
30
30
|
|
31
|
+
## Introduction
|
32
|
+
|
33
|
+
With ActiveRecord, you might write something like this:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Post.where('created_at >= ?', 2.weeks.ago)
|
37
|
+
```
|
38
|
+
|
39
|
+
But then someone tells you, "Hey, you should use Arel!". So you convert your query to use Arel:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Post.where(Post.arel_table[:created_at].gteq(2.weeks.ago))
|
43
|
+
```
|
44
|
+
|
45
|
+
Well, that's great, but it's also pretty verbose. Why don't you give BabySqueel a try:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Post.where.has { created_at >= 2.weeks.ago }
|
49
|
+
```
|
50
|
+
|
51
|
+
#### Quick note
|
52
|
+
|
53
|
+
BabySqueel's blocks use `instance_eval`, which means you won't have access to your instance variables or methods. Don't worry, there's a really easy solution. Just give arity to the block:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
Post.where.has { |post| post.created_at >= 2.weeks.ago }
|
57
|
+
```
|
58
|
+
|
31
59
|
## Usage
|
32
60
|
|
33
61
|
Okay, so we have some models:
|
@@ -151,6 +179,15 @@ Post.joining { author.alias('a').on((author.id == author_id) | (author.name == t
|
|
151
179
|
# INNER JOIN "authors" "a" ON ("authors"."id" = "posts"."author_id" OR "authors"."name" = "posts"."title")
|
152
180
|
```
|
153
181
|
|
182
|
+
##### Grouping
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
Post.selecting { id.count }.grouping { author_id }.when_having { id.count > 5 }
|
186
|
+
# SELECT COUNT("posts"."id") FROM "posts"
|
187
|
+
# GROUP BY "posts"."author_id"
|
188
|
+
# HAVING (COUNT("posts"."id") > 5)
|
189
|
+
```
|
190
|
+
|
154
191
|
##### Functions
|
155
192
|
|
156
193
|
```ruby
|
@@ -172,17 +209,53 @@ Post.joins(:author).where.has {
|
|
172
209
|
# )
|
173
210
|
```
|
174
211
|
|
175
|
-
|
212
|
+
##### Custom SQL Operators
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
authors = Author.selecting { name.op('||', quoted('-dizzle')).as('swag') }
|
216
|
+
# SELECT "authors"."name" || '-dizzle' AS swag FROM "authors"
|
217
|
+
|
218
|
+
authors.first.swag #=> 'Ray Zane-dizzle'
|
219
|
+
```
|
176
220
|
|
177
|
-
|
221
|
+
## Sifters
|
178
222
|
|
179
|
-
|
223
|
+
Sifters are like little snippets of conditions that take parameters.
|
180
224
|
|
181
225
|
```ruby
|
182
|
-
Post
|
183
|
-
|
226
|
+
class Post < ActiveRecord::Base
|
227
|
+
sifter :funny do |str|
|
228
|
+
title == 'rabies'
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
class Author < ActiveRecord::Base
|
233
|
+
sifter :name_contains do |string|
|
234
|
+
name =~ "%#{string}%"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
Post.joins(:author).where.has {
|
239
|
+
sift(:funny) | author.sift(:name_contains, 'blergh')
|
240
|
+
}
|
241
|
+
# SELECT "posts".* FROM "posts"
|
242
|
+
# INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
|
243
|
+
# WHERE ("posts"."title" = 'rabies' OR "authors"."name" LIKE '%blergh%')
|
184
244
|
```
|
185
245
|
|
246
|
+
## What's what?
|
247
|
+
|
248
|
+
The following methods give you access to BabySqueel's DSL:
|
249
|
+
|
250
|
+
| BabySqueel | ActiveRecord Equivalent |
|
251
|
+
|---------------|-------------------------|
|
252
|
+
| `selecting` | `select` |
|
253
|
+
| `ordering` | `order` |
|
254
|
+
| `joining` | `joins` |
|
255
|
+
| `grouping` | `group` |
|
256
|
+
| `where.has` | `where` |
|
257
|
+
| `when_having` | `having` |
|
258
|
+
|
186
259
|
## Development
|
187
260
|
|
188
261
|
1. Pick an ActiveRecord version to develop against, then export it: `export AR=4.2.6`.
|
data/baby_squeel.gemspec
CHANGED
@@ -15,12 +15,9 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.bindir = 'exe'
|
18
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
18
|
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.files =
|
22
|
-
f.match(%r{^(test|spec|features)/})
|
23
|
-
end
|
20
|
+
spec.files = Dir.glob('{lib/**/*,*.{md,txt,gemspec}}')
|
24
21
|
|
25
22
|
spec.add_dependency 'activerecord', '>= 4.0.0'
|
26
23
|
|
data/lib/baby_squeel.rb
CHANGED
@@ -6,6 +6,7 @@ require 'baby_squeel/active_record'
|
|
6
6
|
module BabySqueel
|
7
7
|
end
|
8
8
|
|
9
|
+
::ActiveRecord::Base.extend BabySqueel::ActiveRecord::Sifting
|
9
10
|
::ActiveRecord::Base.extend BabySqueel::ActiveRecord::QueryMethods
|
10
11
|
::ActiveRecord::Relation.prepend BabySqueel::ActiveRecord::QueryMethods
|
11
12
|
::ActiveRecord::QueryMethods::WhereChain.prepend BabySqueel::ActiveRecord::WhereChain
|
@@ -2,10 +2,19 @@ require 'baby_squeel/dsl'
|
|
2
2
|
|
3
3
|
module BabySqueel
|
4
4
|
module ActiveRecord
|
5
|
+
module Sifting
|
6
|
+
def sifter(name, &block)
|
7
|
+
define_singleton_method "sift_#{name}" do |*args|
|
8
|
+
DSL.evaluate_sifter(self, *args, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
module QueryMethods
|
6
14
|
# Constructs Arel for ActiveRecord::Base#joins using the DSL.
|
7
15
|
def joining(&block)
|
8
|
-
|
16
|
+
arel, binds = DSL.evaluate_joins(unscoped, &block)
|
17
|
+
joins(arel).tap { |s| s.bind_values += binds }
|
9
18
|
end
|
10
19
|
|
11
20
|
# Constructs Arel for ActiveRecord::Base#select using the DSL.
|
@@ -17,23 +26,23 @@ module BabySqueel
|
|
17
26
|
def ordering(&block)
|
18
27
|
order DSL.evaluate(self, &block)
|
19
28
|
end
|
29
|
+
|
30
|
+
# Constructs Arel for ActiveRecord::Base#group using the DSL.
|
31
|
+
def grouping(&block)
|
32
|
+
group DSL.evaluate(self, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Constructs Arel for ActiveRecord::Base#having using the DSL.
|
36
|
+
def when_having(&block)
|
37
|
+
having DSL.evaluate(self, &block)
|
38
|
+
end
|
20
39
|
end
|
21
40
|
|
22
41
|
module WhereChain
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
factory = @scope.send(:where_clause_factory)
|
28
|
-
@scope.where_clause += factory.build(opts, [])
|
29
|
-
@scope
|
30
|
-
end
|
31
|
-
else
|
32
|
-
# Constructs Arel for ActiveRecord::Base#where using the DSL.
|
33
|
-
def has(&block)
|
34
|
-
@scope.where_values += [DSL.evaluate(@scope, &block)]
|
35
|
-
@scope
|
36
|
-
end
|
42
|
+
# Constructs Arel for ActiveRecord::Base#where using the DSL.
|
43
|
+
def has(&block)
|
44
|
+
@scope.where! DSL.evaluate(@scope, &block)
|
45
|
+
@scope
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
data/lib/baby_squeel/dsl.rb
CHANGED
@@ -4,9 +4,33 @@ require 'baby_squeel/association'
|
|
4
4
|
|
5
5
|
module BabySqueel
|
6
6
|
class DSL < Table
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class << self
|
8
|
+
# Evaluates a block and unwraps the nodes
|
9
|
+
def evaluate(scope, &block)
|
10
|
+
Nodes.unwrap evaluate!(scope, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Evaluates a block in the context of a DSL instance
|
14
|
+
def evaluate!(scope, &block)
|
15
|
+
new(scope).evaluate(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Evaluates a block specifically for a join. In this
|
19
|
+
# case, we'll return an array of Arel join nodes and
|
20
|
+
# a list of bind parameters.
|
21
|
+
def evaluate_joins(scope, &block)
|
22
|
+
dependency = evaluate!(scope, &block)._arel
|
23
|
+
join_arel = Nodes.unwrap(dependency._arel)
|
24
|
+
[join_arel, dependency.bind_values]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Evaluates a block in the context of a new DSL instance
|
28
|
+
# and passes all arguments to the block.
|
29
|
+
def evaluate_sifter(scope, *args, &block)
|
30
|
+
evaluate scope do |root|
|
31
|
+
root.instance_exec(*args, &block)
|
32
|
+
end
|
33
|
+
end
|
10
34
|
end
|
11
35
|
|
12
36
|
# Create a SQL function. See Arel::Nodes::NamedFunction.
|
@@ -24,13 +48,23 @@ module BabySqueel
|
|
24
48
|
Nodes.wrap Arel::Nodes::NamedFunction.new(name.to_s, args)
|
25
49
|
end
|
26
50
|
|
51
|
+
# See Arel::sql
|
52
|
+
def sql(value)
|
53
|
+
::Arel.sql value
|
54
|
+
end
|
55
|
+
|
56
|
+
# Quotes a string and marks it as SQL
|
57
|
+
def quoted(value)
|
58
|
+
sql _scope.connection.quote(value)
|
59
|
+
end
|
60
|
+
|
27
61
|
# Evaluates a DSL block. If arity is given, this method
|
28
62
|
# `yield` itself, rather than `instance_eval`.
|
29
63
|
def evaluate(&block)
|
30
64
|
if block.arity.zero?
|
31
|
-
|
65
|
+
instance_eval(&block)
|
32
66
|
else
|
33
|
-
|
67
|
+
yield(self)
|
34
68
|
end
|
35
69
|
end
|
36
70
|
|
@@ -1,31 +1,50 @@
|
|
1
1
|
module BabySqueel
|
2
2
|
class JoinDependency
|
3
|
-
|
4
|
-
|
3
|
+
delegate :_scope, :_join, :_on, :_table, to: :@table
|
4
|
+
|
5
|
+
def initialize(table, associations = [])
|
6
|
+
@table = table
|
5
7
|
@associations = associations
|
6
8
|
end
|
7
9
|
|
10
|
+
if ActiveRecord::VERSION::STRING < '4.1.0'
|
11
|
+
def bind_values
|
12
|
+
_scope.joins(join_names(@associations)).bind_values
|
13
|
+
end
|
14
|
+
else
|
15
|
+
def bind_values
|
16
|
+
@bind_values ||= begin
|
17
|
+
relation = _scope.joins(join_names(@associations))
|
18
|
+
relation.arel.bind_values + relation.bind_values
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
8
23
|
# Converts an array of BabySqueel::Associations into an array
|
9
24
|
# of Arel join nodes.
|
10
25
|
#
|
11
26
|
# Each association is built individually so that the correct
|
12
27
|
# Arel join node will be used for each individual association.
|
13
|
-
def
|
14
|
-
|
15
|
-
|
28
|
+
def _arel
|
29
|
+
if _on
|
30
|
+
[_join.new(_table, _on)]
|
31
|
+
else
|
32
|
+
@associations.each.with_index.inject([]) do |joins, (assoc, i)|
|
33
|
+
construct @associations[0..i], joins, assoc._join
|
34
|
+
end
|
16
35
|
end
|
17
36
|
end
|
18
37
|
|
19
38
|
private
|
20
39
|
|
21
|
-
def
|
40
|
+
def construct(associations, theirs, join_node)
|
22
41
|
names = join_names associations
|
23
42
|
mine = build names, join_node
|
24
43
|
theirs + mine[theirs.length..-1]
|
25
44
|
end
|
26
45
|
|
27
46
|
def build(names, join_node)
|
28
|
-
|
47
|
+
_scope.joins(names).join_sources.map do |join|
|
29
48
|
join_node.new(join.left, join.right)
|
30
49
|
end
|
31
50
|
end
|
data/lib/baby_squeel/nodes.rb
CHANGED
@@ -17,7 +17,7 @@ module BabySqueel
|
|
17
17
|
# ActiveRecord.
|
18
18
|
def unwrap(node)
|
19
19
|
if node.respond_to? :_arel
|
20
|
-
node._arel
|
20
|
+
unwrap node._arel
|
21
21
|
elsif node.is_a? Array
|
22
22
|
node.map { |n| unwrap(n) }
|
23
23
|
else
|
@@ -60,13 +60,22 @@ module BabySqueel
|
|
60
60
|
# include necessary/applicable modules.
|
61
61
|
class Generic < Proxy
|
62
62
|
extend Operators::ArelAliasing
|
63
|
-
include Arel::AliasPredication
|
64
|
-
include Arel::OrderPredications
|
65
63
|
include Operators::Comparison
|
66
64
|
include Operators::Equality
|
67
65
|
include Operators::Generic
|
68
66
|
include Operators::Grouping
|
69
67
|
include Operators::Matching
|
68
|
+
|
69
|
+
# Extend the Arel node with some extra modules. For example,
|
70
|
+
# Arel::Nodes::Grouping does not implement Math. InfixOperation doesn't
|
71
|
+
# implement AliasPredication. Without these extensions, the interface
|
72
|
+
# just seems inconsistent.
|
73
|
+
def initialize(node)
|
74
|
+
node.extend Arel::Math
|
75
|
+
node.extend Arel::AliasPredication
|
76
|
+
node.extend Arel::OrderPredications
|
77
|
+
super(node)
|
78
|
+
end
|
70
79
|
end
|
71
80
|
|
72
81
|
class Attribute < Generic
|
@@ -85,7 +94,7 @@ module BabySqueel
|
|
85
94
|
end
|
86
95
|
|
87
96
|
def _arel
|
88
|
-
parent_arel = @parent._arel
|
97
|
+
parent_arel = @parent._arel._arel
|
89
98
|
|
90
99
|
if parent_arel && parent_arel.last
|
91
100
|
parent_arel.last.left[@name]
|
@@ -42,7 +42,7 @@ module BabySqueel
|
|
42
42
|
# * +other+ - The argument to be passed to the SQL operator.
|
43
43
|
#
|
44
44
|
# ==== Example
|
45
|
-
# Post.select { title.op('||', 'diddly') }
|
45
|
+
# Post.select { title.op('||', quoted('diddly')) }
|
46
46
|
# #=> SELECT "posts"."title" || 'diddly' FROM "posts"
|
47
47
|
#
|
48
48
|
def op(operator, other)
|
data/lib/baby_squeel/table.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
require 'baby_squeel/join_dependency'
|
2
2
|
|
3
3
|
module BabySqueel
|
4
|
+
class NotFoundError < StandardError
|
5
|
+
def initialize(model_name, name)
|
6
|
+
super "There is no column or association named '#{name}' for #{model_name}."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
class AssociationNotFoundError < StandardError
|
5
|
-
def initialize(
|
6
|
-
super "Association named '#{name}' was not found
|
11
|
+
def initialize(model_name, name)
|
12
|
+
super "Association named '#{name}' was not found for #{model_name}."
|
7
13
|
end
|
8
14
|
end
|
9
15
|
|
10
16
|
class Table
|
11
|
-
attr_accessor :_on, :_join, :_table
|
17
|
+
attr_accessor :_scope, :_on, :_join, :_table
|
12
18
|
|
13
19
|
def initialize(scope)
|
14
|
-
@
|
20
|
+
@_scope = scope
|
15
21
|
@_table = scope.arel_table
|
16
22
|
@_join = Arel::Nodes::InnerJoin
|
17
23
|
end
|
@@ -24,13 +30,17 @@ module BabySqueel
|
|
24
30
|
# Constructs a new BabySqueel::Association. Raises
|
25
31
|
# an exception if the association is not found.
|
26
32
|
def association(name)
|
27
|
-
if reflection =
|
33
|
+
if reflection = _scope.reflect_on_association(name)
|
28
34
|
Association.new(self, reflection)
|
29
35
|
else
|
30
|
-
raise AssociationNotFoundError.new(
|
36
|
+
raise AssociationNotFoundError.new(_scope.model_name, name)
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
40
|
+
def sift(sifter_name, *args)
|
41
|
+
Nodes.wrap _scope.public_send("sift_#{sifter_name}", *args)
|
42
|
+
end
|
43
|
+
|
34
44
|
# Alias a table. This is only possible when joining
|
35
45
|
# an association explicitly.
|
36
46
|
def alias(alias_name)
|
@@ -79,19 +89,15 @@ module BabySqueel
|
|
79
89
|
# 2. Resolve the assocition's join clauses using ActiveRecord.
|
80
90
|
#
|
81
91
|
def _arel(associations = [])
|
82
|
-
|
83
|
-
_join.new(_table, _on)
|
84
|
-
else
|
85
|
-
JoinDependency.new(@scope, associations).constraints
|
86
|
-
end
|
92
|
+
JoinDependency.new(self, associations)
|
87
93
|
end
|
88
94
|
|
89
95
|
private
|
90
96
|
|
91
97
|
def resolve(name)
|
92
|
-
if
|
98
|
+
if _scope.column_names.include?(name.to_s)
|
93
99
|
self[name]
|
94
|
-
elsif
|
100
|
+
elsif _scope.reflect_on_association(name)
|
95
101
|
association(name)
|
96
102
|
end
|
97
103
|
end
|
@@ -101,10 +107,10 @@ module BabySqueel
|
|
101
107
|
end
|
102
108
|
|
103
109
|
def method_missing(name, *args, &block)
|
104
|
-
if !args.empty? || block_given?
|
105
|
-
|
106
|
-
|
107
|
-
|
110
|
+
return super if !args.empty? || block_given?
|
111
|
+
|
112
|
+
resolve(name) || begin
|
113
|
+
raise NotFoundError.new(_scope.model_name, name)
|
108
114
|
end
|
109
115
|
end
|
110
116
|
end
|
data/lib/baby_squeel/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
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-03-
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -87,16 +87,10 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
-
|
91
|
-
- ".rspec"
|
92
|
-
- ".travis.yml"
|
93
|
-
- Gemfile
|
90
|
+
- CHANGELOG.md
|
94
91
|
- LICENSE.txt
|
95
92
|
- README.md
|
96
|
-
- Rakefile
|
97
93
|
- baby_squeel.gemspec
|
98
|
-
- bin/console
|
99
|
-
- bin/setup
|
100
94
|
- lib/baby_squeel.rb
|
101
95
|
- lib/baby_squeel/active_record.rb
|
102
96
|
- lib/baby_squeel/association.rb
|
@@ -126,8 +120,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
120
|
version: '0'
|
127
121
|
requirements: []
|
128
122
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.4.8
|
130
124
|
signing_key:
|
131
125
|
specification_version: 4
|
132
126
|
summary: A tiny squeel implementation without all of the evil.
|
133
127
|
test_files: []
|
128
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
rvm:
|
4
|
-
- 2.2.4
|
5
|
-
|
6
|
-
before_install: gem install bundler -v 1.11.2
|
7
|
-
after_script: bundle exec rake coveralls:push
|
8
|
-
|
9
|
-
env:
|
10
|
-
global:
|
11
|
-
- COVERALLS_REPO_TOKEN=X5ZWSPW8VW2JXNJO0qNjlZCQNW4ju89gb
|
12
|
-
matrix:
|
13
|
-
- AR=4.0.0
|
14
|
-
- AR=4.1.0
|
15
|
-
- AR=4.1.15
|
16
|
-
- AR=4.2.0
|
17
|
-
- AR=4.2.6
|
18
|
-
- AR=5.0.0.beta2
|
19
|
-
- AR=5.0.0.beta3
|
data/Gemfile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in baby_squeel.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
if ar_version = ENV['AR']
|
7
|
-
gem 'activerecord', ar_version
|
8
|
-
else
|
9
|
-
gem 'activerecord', github: 'rails/rails'
|
10
|
-
end
|
11
|
-
|
12
|
-
group :test do
|
13
|
-
gem 'pry'
|
14
|
-
gem 'coveralls'
|
15
|
-
gem 'simplecov'
|
16
|
-
end
|
17
|
-
|
data/Rakefile
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'open3'
|
3
|
-
require 'bundler/gem_tasks'
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
require 'coveralls/rake/task'
|
6
|
-
|
7
|
-
Coveralls::RakeTask.new
|
8
|
-
|
9
|
-
RSpec::Core::RakeTask.new(:spec)
|
10
|
-
|
11
|
-
def invoke(version, cmd)
|
12
|
-
Bundler.with_clean_env do
|
13
|
-
system({ 'AR' => version, 'SKIPCOV' => '1' }, cmd)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run against a specific ActiveRecord version'
|
18
|
-
task 'spec:version', [:version] do |_, args|
|
19
|
-
if args.version.nil? || args.version.empty?
|
20
|
-
abort 'No version given'
|
21
|
-
end
|
22
|
-
|
23
|
-
FileUtils.rm_rf 'Gemfile.lock'
|
24
|
-
invoke args.version, 'bundle install --quiet'
|
25
|
-
invoke args.version, 'bundle exec rspec -f progress' if $?.success?
|
26
|
-
$stderr.puts "#{args.version} failed." unless $?.success?
|
27
|
-
end
|
28
|
-
|
29
|
-
desc 'Run against all ActiveRecord versions'
|
30
|
-
task 'spec:matrix' do
|
31
|
-
travis = YAML.load_file '.travis.yml'
|
32
|
-
spec_task = Rake::Task['spec:version']
|
33
|
-
|
34
|
-
travis['env']['matrix'].each do |matrix|
|
35
|
-
spec_task.invoke matrix[/\=(.+)$/, 1]
|
36
|
-
spec_task.reenable
|
37
|
-
puts "\n\n"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
task default: :spec
|
data/bin/console
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'baby_squeel'
|
5
|
-
require_relative '../spec/support/schema'
|
6
|
-
require_relative '../spec/support/models'
|
7
|
-
|
8
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
-
# with your gem easier. You can also use a different console, if you like.
|
10
|
-
|
11
|
-
puts 'Creating 2 authors...'
|
12
|
-
authors = [
|
13
|
-
Author.create!(name: 'Ray Zane'),
|
14
|
-
Author.create!(name: 'Jimmy Hoffa')
|
15
|
-
]
|
16
|
-
|
17
|
-
puts 'Creating 15 posts...'
|
18
|
-
15.times do |n|
|
19
|
-
Post.create! title: "Post #{n}", author: authors.sample
|
20
|
-
end
|
21
|
-
|
22
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
23
|
-
|
24
|
-
require 'pry'
|
25
|
-
Pry.start
|