Class: Queries::Citation::Filter

Inherits:
Object
  • Object
show all
Includes:
Concerns::Polymorphic
Defined in:
lib/queries/citation/filter.rb

Overview

!! does not inherit from base query

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Filter) initialize(params)

Returns a new instance of Filter



18
19
20
21
22
23
# File 'lib/queries/citation/filter.rb', line 18

def initialize(params)
  @citation_object_type = params[:citation_object_type]
  @citation_object_id = params[:citation_object_id]
  @source_id = params[:source_id]
  set_polymorphic_ids(params)
end

Instance Attribute Details

- (Object) citation_object_id

Array, Integer



14
15
16
# File 'lib/queries/citation/filter.rb', line 14

def citation_object_id
  @citation_object_id
end

- (Object) citation_object_type

Array, Integer



14
15
16
# File 'lib/queries/citation/filter.rb', line 14

def citation_object_type
  @citation_object_type
end

- (Object) source_id

Array, Integer



14
15
16
# File 'lib/queries/citation/filter.rb', line 14

def source_id
  @source_id
end

Instance Method Details

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


59
60
61
62
63
64
65
# File 'lib/queries/citation/filter.rb', line 59

def all
  if a = and_clauses
    ::Citation.where(and_clauses)
  else
    ::Citation.all
  end
end

- (ActiveRecord::Relation?) and_clauses

Returns:

  • (ActiveRecord::Relation, nil)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/queries/citation/filter.rb', line 26

def and_clauses
  clauses = [
    matching_citation_object_type,
    matching_citation_object_id,
    matching_source_id,
    matching_polymorphic_ids,
  ].compact

  return nil if clauses.empty?

  a = clauses.shift
  clauses.each do |b|
    a = a.and(b)
  end
  a
end

- (Arel::Node?) matching_citation_object_id

Returns:

  • (Arel::Node, nil)


49
50
51
# File 'lib/queries/citation/filter.rb', line 49

def matching_citation_object_id
  citation_object_id.blank? ? nil : table[:citation_object_id].eq(citation_object_id)  
end

- (Arel::Node?) matching_citation_object_type

Returns:

  • (Arel::Node, nil)


44
45
46
# File 'lib/queries/citation/filter.rb', line 44

def matching_citation_object_type
  citation_object_type.blank? ? nil : table[:citation_object_type].eq(citation_object_type) 
end

- (Arel::Node?) matching_source_id

Returns:

  • (Arel::Node, nil)


54
55
56
# File 'lib/queries/citation/filter.rb', line 54

def matching_source_id
  source_id.blank? ? nil : table[:source_id].eq(source_id)  
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


68
69
70
# File 'lib/queries/citation/filter.rb', line 68

def table
  ::Citation.arel_table
end