siphon 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -1
- data/lib/generators/templates/search.rb +3 -3
- data/lib/siphon/adapter.rb +2 -3
- data/lib/siphon/boilerplate.rb +1 -1
- data/lib/siphon/nil.rb +1 -1
- data/lib/siphon/scope.rb +101 -0
- data/lib/siphon/version.rb +1 -1
- data/lib/siphon.rb +2 -1
- data/spec/siphon/base_spec.rb +1 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92365b6395921c463098560d6454e58724e390e16bce4290b2023c3cebded30a
|
4
|
+
data.tar.gz: 6e039cc7825f96ce2d30719216f664534c9a300c8ab48cd4fcdae90cfa27d3f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da28a7c8ff0099c029f7e7133a409f42928521d722d3c4322155829707d07f8ae43bc6458e92145fab8db341a60ee13bbe2a0fa1ad9250a8505a83ae43de6c44
|
7
|
+
data.tar.gz: e32f5534c2f9c620abf63d09caa0da275a2f4bf8ed34ff81e39e0aebddc7c6e09e4434db8b5b5a2fa5959f40c705cbf399cb198ad44a2f6bf04513a0c8c47ecb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## Siphon 0.3.0 (Sep 2018)
|
2
|
+
|
3
|
+
* Rails 5 compat: convert StrongParam to regular params
|
4
|
+
* Decouple Formobj#attributes from Form#obj#siphon_attributes
|
5
|
+
* include Siphon::Scope instead of Boilerplate (use latter for compat)
|
6
|
+
* Formobj.ransack takes type as well
|
7
|
+
|
1
8
|
## Siphon 0.2.4 (Mar 2016)
|
2
9
|
|
3
10
|
* Fixed scopes with no argument still sending nil !
|
@@ -18,7 +25,7 @@
|
|
18
25
|
* The ModelSearch can now respond_to `siphon_attributes`
|
19
26
|
* Boilerplate provides all the stuff ModelSearch needs...
|
20
27
|
* ...hence the generated ModelSearch is now minimal
|
21
|
-
* Boilerplate also gives users a `ransack` macro to set ransack attributes
|
28
|
+
* Boilerplate also gives users a `ransack` macro to set ransack attributes
|
22
29
|
|
23
30
|
## Siphon 0.1.3
|
24
31
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# uncomment `q` lines for combining ransack with your scope search
|
2
2
|
class <%= class_name %>Search
|
3
3
|
|
4
|
-
include Siphon::
|
4
|
+
include Siphon::Scope
|
5
5
|
siphonize <%= class_mate %>
|
6
6
|
|
7
7
|
#
|
@@ -21,7 +21,7 @@ class <%= class_name %>Search
|
|
21
21
|
@relation = relation
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
24
|
+
# Example of Search Form handling order stuff (might not be the best place)
|
25
25
|
def self.order_by
|
26
26
|
[['newest',"#{table_name}.created_at DESC"],
|
27
27
|
["oldest", "#{table_name}.created_at"],
|
@@ -34,4 +34,4 @@ class <%= class_name %>Search
|
|
34
34
|
def order_by=( val )
|
35
35
|
@order_by = val.blank? ? "#{table_name}.created_at DESC" : val
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
data/lib/siphon/adapter.rb
CHANGED
@@ -48,8 +48,7 @@ module Siphon
|
|
48
48
|
# if the form object has #siphon_attributes favor that one
|
49
49
|
# usefull to seperate ransack attributes from siphon ones
|
50
50
|
def assign_scope_hashes(formobj)
|
51
|
-
formobj.respond_to?(:siphon_attributes) ?
|
52
|
-
formobj.siphon_attributes : formobj.attributes
|
51
|
+
formobj.respond_to?(:siphon_attributes) ? formobj.siphon_attributes : formobj.attributes
|
53
52
|
end
|
54
53
|
end
|
55
|
-
end
|
54
|
+
end
|
data/lib/siphon/boilerplate.rb
CHANGED
data/lib/siphon/nil.rb
CHANGED
data/lib/siphon/scope.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module Siphon
|
4
|
+
module Scope
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include ActiveModel::Model
|
9
|
+
include Virtus.model
|
10
|
+
include InstanceMethods
|
11
|
+
|
12
|
+
cattr_accessor :model
|
13
|
+
cattr_accessor :model_name
|
14
|
+
cattr_accessor :table_name
|
15
|
+
|
16
|
+
|
17
|
+
attr_reader :ransack_attributes # for the Ransack object
|
18
|
+
attr_reader :siphon_attributes # for the Siphon object
|
19
|
+
attr_reader :order_by # handles your order clause
|
20
|
+
end
|
21
|
+
|
22
|
+
module InstanceMethods
|
23
|
+
def initialize( params = {})
|
24
|
+
@params = convert_to_hash(params)
|
25
|
+
super @params
|
26
|
+
|
27
|
+
@ransack_attributes = attributes.slice(*self.class.ransack_set)
|
28
|
+
@siphon_attributes = attributes.slice(*self.class.siphon_set)
|
29
|
+
|
30
|
+
self.order_by = @params["order_by"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert_to_hash(params)
|
34
|
+
if params.nil?
|
35
|
+
{}
|
36
|
+
elsif params.respond_to?(:permit!)
|
37
|
+
params.permit!
|
38
|
+
elsif params.respond_to?(:with_indifferent_access)
|
39
|
+
params.with_indifferent_access
|
40
|
+
else
|
41
|
+
params
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def table_name
|
46
|
+
self.class.model.table_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def ransack
|
50
|
+
@relation.search(ransack_attributes)
|
51
|
+
end
|
52
|
+
|
53
|
+
def merge(relation)
|
54
|
+
@relation = @relation.merge(relation)
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def siphoned
|
59
|
+
Siphon::Base.new(@relation).scope( self )
|
60
|
+
end
|
61
|
+
|
62
|
+
# memoized or it'll break after attributes reconciled
|
63
|
+
def result
|
64
|
+
@result ||= siphoned.merge(ransack.result)
|
65
|
+
end
|
66
|
+
|
67
|
+
def preformat_date(value = nil)
|
68
|
+
value.is_a?(String) && value.present? ? Date.strptime(value, I18n.t('date.formats.long')) : value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class_methods do
|
73
|
+
|
74
|
+
def siphonize(model, model_name: nil, table_name: nil)
|
75
|
+
name = model_name || "#{model}Search"
|
76
|
+
self.model_name= ActiveModel::Name.new(self, nil, name)
|
77
|
+
self.table_name= model.table_name
|
78
|
+
@ransack_set ||= []
|
79
|
+
@siphon_set ||= []
|
80
|
+
end
|
81
|
+
|
82
|
+
def ransack_set
|
83
|
+
@ransack_set
|
84
|
+
end
|
85
|
+
|
86
|
+
def siphon_set
|
87
|
+
@siphon_set
|
88
|
+
end
|
89
|
+
|
90
|
+
def scope(attr, type = nil)
|
91
|
+
type.nil? ? attribute(attr) : attribute(attr, type)
|
92
|
+
@siphon_set << attr
|
93
|
+
end
|
94
|
+
|
95
|
+
def ransack(attr, type = nil)
|
96
|
+
type.nil? ? attribute(attr) : attribute(attr, type)
|
97
|
+
@ransack_set << attr
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/siphon/version.rb
CHANGED
data/lib/siphon.rb
CHANGED
@@ -8,6 +8,7 @@ require "siphon/base"
|
|
8
8
|
require "siphon/adapter"
|
9
9
|
require "siphon/nil"
|
10
10
|
require "siphon/boilerplate"
|
11
|
+
require "siphon/scope"
|
11
12
|
|
12
13
|
module Siphon
|
13
14
|
# Your code goes here...
|
@@ -20,4 +21,4 @@ end
|
|
20
21
|
|
21
22
|
ActiveSupport.on_load :action_controller do
|
22
23
|
include Siphon
|
23
|
-
end
|
24
|
+
end
|
data/spec/siphon/base_spec.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.
|
4
|
+
version: 0.3.0
|
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: 2018-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/siphon/base.rb
|
137
137
|
- lib/siphon/boilerplate.rb
|
138
138
|
- lib/siphon/nil.rb
|
139
|
+
- lib/siphon/scope.rb
|
139
140
|
- lib/siphon/version.rb
|
140
141
|
- siphon.gemspec
|
141
142
|
- spec/class/active_relation.rb
|
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
167
|
version: '0'
|
167
168
|
requirements: []
|
168
169
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.6
|
170
|
+
rubygems_version: 2.7.6
|
170
171
|
signing_key:
|
171
172
|
specification_version: 4
|
172
173
|
summary: Siphon enables you to easily apply/combine/exclude your ActiveRecord scopes
|