Module: Siphon::Scope::InstanceMethods
- Defined in:
- lib/siphon/scope.rb
Instance Method Summary collapse
- #convert_to_hash(params) ⇒ Object
- #initialize(params = {}) ⇒ Object
- #merge(relation) ⇒ Object
- #preformat_date(value = nil) ⇒ Object
- #ransack ⇒ Object
-
#result ⇒ Object
memoized or it’ll break after attributes reconciled.
- #siphoned ⇒ Object
- #table_name ⇒ Object
Instance Method Details
#convert_to_hash(params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# 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 |
#initialize(params = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# 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 |
#merge(relation) ⇒ Object
52 53 54 55 |
# File 'lib/siphon/scope.rb', line 52 def merge(relation) @relation = @relation.merge(relation) self end |
#preformat_date(value = nil) ⇒ Object
66 67 68 |
# 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 ⇒ Object
48 49 50 |
# File 'lib/siphon/scope.rb', line 48 def ransack @relation.ransack(ransack_attributes) end |
#result ⇒ Object
memoized or it’ll break after attributes reconciled
62 63 64 |
# File 'lib/siphon/scope.rb', line 62 def result @result ||= siphoned.merge(ransack.result) end |
#siphoned ⇒ Object
57 58 59 |
# File 'lib/siphon/scope.rb', line 57 def siphoned Siphon::Base.new(@relation).scope( self ) end |
#table_name ⇒ Object
44 45 46 |
# File 'lib/siphon/scope.rb', line 44 def table_name self.class.model.table_name end |