Module: ActiveRecord::Filters::Base

Included in:
Filter
Defined in:
lib/active_record/filters/base.rb

Instance Method Summary collapse

Instance Method Details

#associationObject



12
13
14
# File 'lib/active_record/filters/base.rb', line 12

def association
  @association ||= klass.reflect_on_association(options[:using]) if association?
end

#association?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/active_record/filters/base.rb', line 16

def association?
  options.key?(:using)
end

#column_struct(column, name) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/active_record/filters/base.rb', line 28

def column_struct(column, name)
  type     = name.is_a?(Hash) ? name.values.first : column.type
  relation = column.try :relation

  OpenStruct.new(relation: relation,
                 name: column.name,
                 type: type)
end

#find_column(klass, name) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/active_record/filters/base.rb', line 20

def find_column(klass, name)
  column_name = name.is_a?(Hash) ? name.keys.first : name

  table_column = klass.arel_table.engine.columns.detect { |column| column.name.to_sym == column_name.to_sym }

  column_struct(table_column, name) if table_column
end

#scopedObject



4
5
6
7
8
9
10
# File 'lib/active_record/filters/base.rb', line 4

def scoped
  @scoped ||= if association
                klass.joins(association.name)
              else
                klass.all
  end
end