class Siphon::Adapter

Adapter

use : determine which scope will not be called &

set args to nil for 'argless' scopes

Public Class Methods

new(formobj) click to toggle source
# File lib/siphon/adapter.rb, line 12
def initialize(formobj)
  @formobj = formobj

  @scopes_hash = assign_scope_hashes @formobj
  @argless     = argless_list @formobj
end

Public Instance Methods

call() click to toggle source
# File lib/siphon/adapter.rb, line 19
def call
  filterout_empty_string_and_nil
  apply_nil_on_argless_scopes
end

Private Instance Methods

apply_nil_on_argless_scopes() click to toggle source

scope with no args are listed in @argless we loop & set their arg to nil (aka: no arg with splat) must be called AFTER filterout_empty_string_and_nil

# File lib/siphon/adapter.rb, line 35
def apply_nil_on_argless_scopes
  @argless.each {|scope, v| @scopes_hash[scope]= nil if @scopes_hash[scope] }
  @scopes_hash
end
argless_list(formobj) click to toggle source

list of virtus attributes with Siphon::Nil type

# File lib/siphon/adapter.rb, line 41
def argless_list(formobj)
  formobj.class.
    attribute_set.
    select {|a| a.class == Siphon::Nil}.
    map(&:name)
end
assign_scope_hashes(formobj) click to toggle source

if the form object has siphon_attributes favor that one usefull to seperate ransack attributes from siphon ones

# File lib/siphon/adapter.rb, line 50
def assign_scope_hashes(formobj)
  formobj.respond_to?(:siphon_attributes) ? formobj.siphon_attributes : formobj.attributes
end
filterout_empty_string_and_nil() click to toggle source

Do NOT APPLY SCOPE && reject them from scopes_hash

  1. if scope is present in form but with no value (aka: an empty string)

  2. if present in formobj but not in form (aka : a nil value)

# File lib/siphon/adapter.rb, line 28
def filterout_empty_string_and_nil
  @scopes_hash.delete_if { |scope, arg| ["", nil].include? @formobj[scope] }
end