siphon 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/README.md +10 -0
- data/Rakefile +4 -0
- data/lib/generators/siphon_generator.rb +7 -0
- data/lib/generators/templates/search.rb +59 -0
- data/lib/siphon/base.rb +6 -2
- data/lib/siphon/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fda2150f53756f1efb9c4b7799ef8b455058da6
|
4
|
+
data.tar.gz: bf50ec379b961877f30111e9a692f9acb3725fc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf69ad74e5e7e24674f8c79b085cd8d44099dbf22f4ad6d096f714d6295d7fa49a3b95f277d04c906b6a4bbf5bb7a62d846bae5ccb75b7ebca0c60449b38fcbc
|
7
|
+
data.tar.gz: 67d175542ffade84c13ce2116730d96f7c2fd6841b32e35938d90953ea79069df248e2743268c2815afc859b0929317f4641c191d2072777d6a91c9b2f72cbc5
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -98,6 +98,12 @@ In the case of `unpaid` siphon knows it doesn't take any argument (Siphon::Nil)
|
|
98
98
|
|
99
99
|
That's all!
|
100
100
|
|
101
|
+
## Alternate Libs
|
102
|
+
|
103
|
+
* [has_scope](https://github.com/plataformatec/has_scope)
|
104
|
+
* [periscope](https://github.com/laserlemon/periscope)
|
105
|
+
* [scoped_from](https://github.com/alexistoulotte/scoped_from)
|
106
|
+
|
101
107
|
## Contributing
|
102
108
|
|
103
109
|
1. Fork it
|
@@ -108,3 +114,7 @@ That's all!
|
|
108
114
|
|
109
115
|
[1]: https://github.com/solnic/virtus
|
110
116
|
[2]: https://coderwall.com/p/4zz6ca
|
117
|
+
|
118
|
+
|
119
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
120
|
+
|
data/Rakefile
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
# uncomment `q` lines for combining ransack with your scope search
|
2
|
+
class <%= class_name %>Search
|
3
|
+
|
4
|
+
include ActiveModel::Model
|
5
|
+
include Virtus.model
|
6
|
+
|
7
|
+
TABLE = <%= class_name %>.table_name
|
8
|
+
|
9
|
+
attribute :tree_id, Integer
|
10
|
+
attribute :is_public, Boolean
|
11
|
+
|
12
|
+
|
13
|
+
attr_reader :q # the nested ransack object
|
14
|
+
attr_reader :order_by # handles your order clause
|
15
|
+
|
16
|
+
def initialize(params = {})
|
17
|
+
@params = params || {}
|
18
|
+
super(params)
|
19
|
+
self.q= @params[:q]
|
20
|
+
self.order_by= @params[:order_by]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Example of conditionally applying search terms.
|
24
|
+
# def done
|
25
|
+
# return false unless @params[:q]
|
26
|
+
# @params[:q][:state_eq].blank? ? @done : ""
|
27
|
+
# end
|
28
|
+
|
29
|
+
def result
|
30
|
+
<%= class_name %>.scoped.order(order_by).merge(q.result).merge(siphoned)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Exmaple of Search Form handling order stuff (might not be the best place)
|
34
|
+
def self.order_by
|
35
|
+
[['newest',"#{TABLE}.created_at DESC"],
|
36
|
+
["oldest", "#{TABLE}.created_at"],
|
37
|
+
["category", "#{TABLE}.category_id, #{TABLE}.id"]
|
38
|
+
# ["popularity", "sales_num DESC"]]
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Example of default ordering
|
43
|
+
def order_by=( val )
|
44
|
+
@order_by = val.blank? ? "#{TABLE}.created_at DESC" : val
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def q=(sub_form_hash = {})
|
49
|
+
@q = <%= class_name %>.search( sub_form_hash )
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def siphoned
|
55
|
+
Siphon::Base.new(<%= class_name %>.scoped).scope( self )
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
data/lib/siphon/base.rb
CHANGED
@@ -20,11 +20,15 @@ module Siphon
|
|
20
20
|
scopes_hash = Siphon::Adapter.new(formobject).call
|
21
21
|
|
22
22
|
scopes_hash.each do |meth, arg|
|
23
|
-
self.relation =
|
23
|
+
self.relation = if arg.is_a?(Array)
|
24
|
+
relation.send(meth, *arg)
|
25
|
+
else
|
26
|
+
relation.send(meth, arg)
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
relation
|
27
31
|
end
|
28
32
|
|
29
33
|
end # Base
|
30
|
-
end
|
34
|
+
end
|
data/lib/siphon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: siphon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Sistovaris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -120,11 +120,14 @@ files:
|
|
120
120
|
- .pryrc
|
121
121
|
- .rspec
|
122
122
|
- .ruby-version
|
123
|
+
- .travis.yml
|
123
124
|
- Gemfile
|
124
125
|
- LICENSE.txt
|
125
126
|
- README.md
|
126
127
|
- Rakefile
|
127
128
|
- TODO.md
|
129
|
+
- lib/generators/siphon_generator.rb
|
130
|
+
- lib/generators/templates/search.rb
|
128
131
|
- lib/siphon.rb
|
129
132
|
- lib/siphon/adapter.rb
|
130
133
|
- lib/siphon/base.rb
|
@@ -159,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
162
|
version: '0'
|
160
163
|
requirements: []
|
161
164
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.0
|
165
|
+
rubygems_version: 2.2.0
|
163
166
|
signing_key:
|
164
167
|
specification_version: 4
|
165
168
|
summary: Siphon enables you to easily apply/combine/exclude your ActiveRecord scopes
|
@@ -173,3 +176,4 @@ test_files:
|
|
173
176
|
- spec/siphon/mapper_spec.rb
|
174
177
|
- spec/siphon_spec.rb
|
175
178
|
- spec/spec_helper.rb
|
179
|
+
has_rdoc:
|