gauze 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/gauze.gemspec +2 -0
- data/lib/gauze.rb +0 -1
- data/lib/gauze/base.rb +23 -3
- data/lib/gauze/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2e3f518dd71ce727fe94b67cd76d74c949c5e8a
|
4
|
+
data.tar.gz: 9e308e8bea3e14e4c750c01eaea2a9a5a28cedbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9ea811399e221c4cbd38e5cbceed77d6cee6e6a5bf4756289441a1d1a213d80c0b144512fb60199e4a8636f5517b119cabe5a89ee08b0f90283f1c8f419abd
|
7
|
+
data.tar.gz: 93d44f6f4c34e350f995b76b9f89638ef53c8b920aa222426e96ca5adc13b0256dfd4770d65c3efcb0a7a6a18424467d83ebe9465fc722e076f66a45f708fe08
|
data/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
![](http://cdn.flaticon.com/png/256/33311.png)
|
1
2
|
# Gauze
|
2
3
|
|
3
|
-
|
4
|
+
Translating filtering & sorting params to AR scopes can be teadious and doesn't belong in your controllers...
|
5
|
+
|
6
|
+
Enter **Gauze**
|
7
|
+
|
8
|
+
Gauze allows you to build very simple service objects to be called from your controllers and passed the resource & params.
|
9
|
+
|
10
|
+
Read on below to see how it works.
|
4
11
|
|
5
12
|
## Installation
|
6
13
|
|
@@ -24,6 +31,7 @@ Create a class that your controller can find.
|
|
24
31
|
Define filters using the Gauze DSL.
|
25
32
|
|
26
33
|
The filter method accepts 4 arguments.
|
34
|
+
|
27
35
|
`filter :param_key, :column_name, :arel_method, :preprocessor`
|
28
36
|
|
29
37
|
* `:param_key` - The key to look for when params are passed in.
|
@@ -48,8 +56,8 @@ Then in your controller:
|
|
48
56
|
end
|
49
57
|
```
|
50
58
|
|
51
|
-
Because
|
52
|
-
```
|
59
|
+
Because **Gauze** uses AREL to construct queries, you can use `.build` just like any other scope. You can pass relational objects & chain more relations as you need.
|
60
|
+
```ruby
|
53
61
|
def index
|
54
62
|
@events = EventFilters.build(current_user.events, params).order(created_at: :desc).where(name: "Football Game")
|
55
63
|
render json: @events
|
data/gauze.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "rails", ">= 3.2.0"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
25
|
end
|
data/lib/gauze.rb
CHANGED
data/lib/gauze/base.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
module Gauze
|
2
2
|
class Base
|
3
|
+
def self.needs(*join_stanza)
|
4
|
+
@join_stanza ||= nil
|
5
|
+
case @join_stanza
|
6
|
+
when nil
|
7
|
+
@join_stanza = join_stanza
|
8
|
+
when Array
|
9
|
+
@join_stanza.push(join_stanza)
|
10
|
+
when Hash
|
11
|
+
@join_stanza.merge!(join_stanza)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
def self.filter(param_key, column_name, arel_method, preprocessor = nil)
|
4
|
-
|
5
|
-
|
16
|
+
@filters ||= []
|
17
|
+
@filters.push param_key: param_key, column: column_name, method: arel_method, preprocessor: preprocessor
|
6
18
|
end
|
7
19
|
|
8
20
|
def self.build(resource, params = {})
|
@@ -18,6 +30,11 @@ module Gauze
|
|
18
30
|
wheres = applied_filters.map {|obj| build_arel_filter(obj)}
|
19
31
|
_query = @resource
|
20
32
|
wheres.each {|node| _query = _query.where(node)}
|
33
|
+
|
34
|
+
if self.class.instance_variable_get(:@join_stanza).present?
|
35
|
+
_query = _query.joins(self.class.instance_variable_get(:@join_stanza))
|
36
|
+
end
|
37
|
+
|
21
38
|
return _query
|
22
39
|
end
|
23
40
|
|
@@ -29,11 +46,14 @@ module Gauze
|
|
29
46
|
end
|
30
47
|
|
31
48
|
private
|
49
|
+
def arel_column(hash_param)
|
50
|
+
end
|
51
|
+
|
32
52
|
def applied_filters
|
33
53
|
_filters = []
|
34
54
|
@params.each do |k,v|
|
35
55
|
next unless v.present?
|
36
|
-
next unless filter =
|
56
|
+
next unless filter = self.class.instance_variable_get(:@filters).find {|obj| obj[:param_key] == k}
|
37
57
|
_filters.push filter
|
38
58
|
end
|
39
59
|
|
data/lib/gauze/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gauze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Ostrowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|