Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f77dd1

Browse files
committed
let the formobject respond_to siphon_attributes instead of attributes (handy to distinguish ransack from scope attrs)
1 parent b5a8eac commit 6f77dd1

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

lib/siphon/adapter.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class Adapter
1212
def initialize(formobj)
1313
@formobj = formobj
1414

15-
@scopes_hash = @formobj.attributes
16-
@argless = argless_list(formobj)
15+
@scopes_hash = assign_scope_hashes @formobj
16+
@argless = argless_list @formobj
1717
end
1818

1919
def call
@@ -22,9 +22,9 @@ def call
2222
end
2323

2424
private
25-
# if scope is present in form but with no value (aka: an empty string)
26-
# or if present in formobj but not in form (aka : a nil value)
27-
# don't apply the scope && reject them from scopes_hash
25+
# Do NOT APPLY SCOPE && reject them from scopes_hash
26+
# 1. if scope is present in form but with no value (aka: an empty string)
27+
# 2. if present in formobj but not in form (aka : a nil value)
2828
def filterout_empty_string_and_nil
2929
@scopes_hash.delete_if { |scope, arg| ["", nil].include? @formobj[scope] }
3030
end
@@ -45,5 +45,11 @@ def argless_list(formobj)
4545
map(&:name)
4646
end
4747

48+
# if the form object has #siphon_attributes favor that one
49+
# usefull to seperate ransack attributes from siphon ones
50+
def assign_scope_hashes(formobj)
51+
formobj.respond_to?(:siphon_attributes) ?
52+
formobj.siphon_attributes : formobj.attributes
53+
end
4854
end
4955
end

0 commit comments

Comments
 (0)