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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1357a1cf69d1fb2335125717970b9566f92fd59a
4
- data.tar.gz: 5d01f2843bb9144cb5f5dcd2d59bb538e7538466
3
+ metadata.gz: e2e3f518dd71ce727fe94b67cd76d74c949c5e8a
4
+ data.tar.gz: 9e308e8bea3e14e4c750c01eaea2a9a5a28cedbe
5
5
  SHA512:
6
- metadata.gz: 61489eb63d26269ee43122f96a86c640a424976f6a22165198c4ccad1bf6e0c0e8146d97f0c27c7f8f4504f6691a83e427e0518696d24a9d5269abffe6d7d953
7
- data.tar.gz: 2587dc546e1375d6523e633301a38b1f0cbe44d9a677043cd4b7284c86fd2e7c8b1339bdfa31c0023950a993d0118f4214a9f771212ce16e8f70e494808c0fe2
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
- TODO: Write a gem description
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 *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.
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
@@ -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
@@ -2,5 +2,4 @@ require "gauze/version"
2
2
  require "gauze/base"
3
3
 
4
4
  module Gauze
5
- # Your code goes here...
6
5
  end
@@ -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
- @@filters ||= []
5
- @@filters.push param_key: param_key, column: column_name, method: arel_method, preprocessor: preprocessor
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 = @@filters.find {|obj| obj[:param_key] == k}
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
 
@@ -1,3 +1,3 @@
1
1
  module Gauze
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-13 00:00:00.000000000 Z
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