siphon 0.1.2 → 0.1.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: cade992dddbcf4aaed6af0409efc20205c03e48e
4
- data.tar.gz: 3ac950dbd0d3ac66a9681193733cc9f363c6da20
3
+ metadata.gz: 0fda2150f53756f1efb9c4b7799ef8b455058da6
4
+ data.tar.gz: bf50ec379b961877f30111e9a692f9acb3725fc4
5
5
  SHA512:
6
- metadata.gz: d6d8a170387014c505b1c1f31dd42d7dc5e4b49455f9d8851c80da5a911e74ac8c0a2aeb4b294dff56c2d7d989fd1efdba8f9b1cc045d3fe00c0ce307776bdba
7
- data.tar.gz: ce48cab6fc0e4174fe8f20479daa7f23b118c2574281f3e0881799cbf98b3485f02c6859d98221fdb9f82ded4d6b3e6ba0cd0d19c88303a654dd9c7b03bafb16
6
+ metadata.gz: cf69ad74e5e7e24674f8c79b085cd8d44099dbf22f4ad6d096f714d6295d7fa49a3b95f277d04c906b6a4bbf5bb7a62d846bae5ccb75b7ebca0c60449b38fcbc
7
+ data.tar.gz: 67d175542ffade84c13ce2116730d96f7c2fd6841b32e35938d90953ea79069df248e2743268c2815afc859b0929317f4641c191d2072777d6a91c9b2f72cbc5
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ #- jruby-18mode # JRuby in 1.8 mode
6
+ #- jruby-19mode # JRuby in 1.9 mode
7
+ #- rbx
8
+ # uncomment this line if your project needs to run something other than `rake`:
9
+ # script: bundle exec rspec spec
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
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/charly/siphon/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
120
+
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ class SiphonGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path("../templates", __FILE__)
3
+
4
+ def create_search_file
5
+ template "search.rb", File.join('app/siphon', class_path, "#{file_name}_search.rb")
6
+ end
7
+ end
@@ -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 = relation.send(meth, *arg)
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
@@ -1,3 +1,3 @@
1
1
  module Siphon
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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: 2013-12-06 00:00:00.000000000 Z
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.3
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: