module Siphon::Scope::InstanceMethods
Public Class Methods
new( params = {})
click to toggle source
Calls superclass method
# File lib/siphon/scope.rb, line 22 def initialize( params = {}) @params = convert_to_hash(params) super @params @ransack_attributes = attributes.slice(*self.class.ransack_set) @siphon_attributes = attributes.slice(*self.class.siphon_set) self.order_by = @params["order_by"] end
Public Instance Methods
convert_to_hash(params)
click to toggle source
# File lib/siphon/scope.rb, line 32 def convert_to_hash(params) if params.nil? {} elsif params.respond_to?(:permit!) params.permit! elsif params.respond_to?(:with_indifferent_access) params.with_indifferent_access else params end end
merge(relation)
click to toggle source
# File lib/siphon/scope.rb, line 52 def merge(relation) @relation = @relation.merge(relation) self end
preformat_date(value = nil)
click to toggle source
# File lib/siphon/scope.rb, line 66 def preformat_date(value = nil) value.is_a?(String) && value.present? ? Date.strptime(value, I18n.t('date.formats.long')) : value end
ransack()
click to toggle source
# File lib/siphon/scope.rb, line 48 def ransack @relation.ransack(ransack_attributes) end
result()
click to toggle source
memoized or it'll break after attributes reconciled
# File lib/siphon/scope.rb, line 62 def result @result ||= siphoned.merge(ransack.result) end
siphoned()
click to toggle source
# File lib/siphon/scope.rb, line 57 def siphoned Siphon::Base.new(@relation).scope( self ) end
table_name()
click to toggle source
# File lib/siphon/scope.rb, line 44 def table_name self.class.model.table_name end