queryable 2.1.0 → 2.1.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: 137ea28c0dc8498a7dcb8044dfe22916e852e058
4
- data.tar.gz: 50a904195d630da9e2286397ac90ebd8d9ff0171
3
+ metadata.gz: 47991b347fa04e683c64a77a520c71e01891b471
4
+ data.tar.gz: 5cd9cece435510a6c432fc82230333c62d7f3b36
5
5
  SHA512:
6
- metadata.gz: 0a71dee62ef6250e7e285935baa14b8bcfb336e5c862dab8a7528e12bbe486fd69a5f34e22abfb9bb6db2689710077d242d60e810b45f2b7c95400ce2cf6af33
7
- data.tar.gz: d2ae50700d887071e93623387906cc62c36087918d45d64c1091999bea13621da380f9c1f047cb24e4fdf02f1d436ba62cb8ed94686dfe439ef0de2f7c1f1d1b
6
+ metadata.gz: a647c943402b09005f4d58b14013f7e366eea865e6e86b2050bc04a5b7f26dd552874e1e2ea27ff6e22f9f0ded5d2f58a070f2e089f5abff396e27fdd9a4d233
7
+ data.tar.gz: d47b1fc13ac6a04a158f91714d85d5e6674b6e29b827d87f5a75b461c32a171086ce7d52d5c9c4a92160596038c5b4e1303edad562261e87e69252602fcb4d26
data/README.md CHANGED
@@ -2,6 +2,7 @@ Queryable
2
2
  =====================
3
3
  [![Gem Version](https://badge.fury.io/rb/queryable.svg)](http://badge.fury.io/rb/queryable)
4
4
  [![Build Status](https://travis-ci.org/ElMassimo/queryable.svg)](https://travis-ci.org/ElMassimo/queryable)
5
+ [![Test Coverage](https://codeclimate.com/github/ElMassimo/queryable/badges/coverage.svg)](https://codeclimate.com/github/ElMassimo/queryable)
5
6
  [![Code Climate](https://codeclimate.com/github/ElMassimo/queryable.png)](https://codeclimate.com/github/ElMassimo/queryable)
6
7
  [![Inline docs](http://inch-ci.org/github/ElMassimo/queryable.svg)](http://inch-ci.org/github/ElMassimo/queryable)
7
8
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/queryable/blob/master/LICENSE.txt)
@@ -13,18 +14,6 @@ Queryable is a mixin that allows you to easily define query objects with chainab
13
14
 
14
15
  Scopes serve to encapsulate reusable business rules, a method is defined with
15
16
  the selected name and block (or proc)
16
-
17
- ### Delegation
18
-
19
- By default most Array methods are delegated to the internal query. It's possible
20
- to delegate extra methods to the query by calling `delegate`.
21
- ```ruby
22
- def CustomersQuery
23
- delegate :update_all, :destroy_all
24
- end
25
- ```
26
-
27
- ## Usage
28
17
  ```ruby
29
18
  class CustomersQuery
30
19
  include Queryable
@@ -50,22 +39,26 @@ end
50
39
  CustomerQuery.new(shop.customers).miller_fans
51
40
  ```
52
41
 
42
+ ### Delegation
43
+
44
+ By default most Array methods are delegated to the internal query. It's possible
45
+ to delegate extra methods to the query by calling `delegate`.
46
+ ```ruby
47
+ def CustomersQuery
48
+ delegate :update_all, :destroy_all
49
+ end
50
+ ```
51
+
53
52
  ## Advantages
54
53
 
55
54
  * Query objects are easy to understand.
56
55
  * You can inherit, mixin, and chain queries in a very natural way.
57
56
  * Increased testability, pretty close to being ORM/ODM agnostic.
58
57
 
59
- ## Testing
60
-
61
- You can check the [specs](https://github.com/ElMassimo/queryable/tree/master/spec) of the project
62
- to check how to test query objects without even having to require the ORM/ODM, or
63
- you can test by requiring your ORM/ODM and executing queries as usual.
64
-
65
58
  ## Optional Modules
66
- Besides Queryable, there are three opt-in modules that can help you when creating
67
- query objects. These modules would need to be manually required during app
68
- initialization or wherever necessary (in Rails, config/initializers).
59
+ There are three opt-in modules that can help you when creating query objects.
60
+ These modules would need to be manually required during app initialization or
61
+ wherever necessary (in Rails, config/initializers).
69
62
 
70
63
  ### DefaultQuery
71
64
  Provides default initialization for query objects, by attempting to infer the
@@ -89,6 +82,7 @@ OldCustomersQuery.new.queryable == ArchivedCustomers.all
89
82
  ```
90
83
  If you want to use common base objects for your queries, you may want want to
91
84
  delay the automatic inference:
85
+
92
86
  ```ruby
93
87
  class BaseQuery
94
88
  include Queryable
@@ -130,7 +124,7 @@ BigCustomersQuery.new.queryable ==
130
124
  Customer.where(:last_purchase.gt => 7.days.ago, :total_expense.gt => 9999999)
131
125
  ```
132
126
 
133
- ### Chainable Methods
127
+ ### Chainable
134
128
 
135
129
  While scopes are great because of their terseness, they can be limiting because
136
130
  the block executes in the context of the internal query, so methods, constants,
@@ -175,8 +169,9 @@ To avoid repetition, it's a good idea to create a `BaseQuery` object
175
169
  to contain both the modules inclusion, and common scopes you may reuse.
176
170
 
177
171
  ```ruby
178
- require 'queryable/default_query'
172
+ require 'queryable/chainable'
179
173
  require 'queryable/default_scope'
174
+ require 'queryable/default_query'
180
175
 
181
176
  def BaseQuery
182
177
  include Queryable
@@ -197,6 +192,12 @@ def CustomersQuery < BaseQuery
197
192
  end
198
193
  ```
199
194
 
195
+ ## Testing
196
+
197
+ You can check the [specs](https://github.com/ElMassimo/queryable/tree/master/spec) of the project
198
+ to check how to test query objects without even having to require the ORM/ODM, or
199
+ you can test by requiring your ORM/ODM and executing queries as usual.
200
+
200
201
  ## RDocs
201
202
 
202
203
  You can view the **Queryable** documentation in RDoc format here:
data/lib/queryable.rb CHANGED
@@ -38,7 +38,8 @@ module Queryable
38
38
 
39
39
  # Public: Delegates the specified methods to the internal query.
40
40
  def delegate(*methods)
41
- methods.last.is_a?(Hash) ? super : def_delegators(:queryable, *methods)
41
+ to = methods.last.is_a?(Hash) && methods.pop[:to] || :queryable
42
+ def_delegators(to == :class ? 'self.class' : to, *methods)
42
43
  end
43
44
 
44
45
  # Public: Defines a new method that executes the passed proc or block in
@@ -25,7 +25,6 @@ module Queryable
25
25
  def chain(*names)
26
26
  prepend Module.new.tap { |m| Chainable.add_scope_methods(m, names) }
27
27
  end
28
-
29
28
  end
30
29
 
31
30
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queryable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-20 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Queryable is a module that encapsulates query building so you don't have
14
14
  to tuck scopes inside your models.