Class: Queries::BiologicalAssociation::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/queries/biological_association/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



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

def initialize(params)
  @subject_global_id = params[:subject_global_id]
  @object_global_id = params[:object_global_id]
  @biological_relationship_id = params[:biological_relationship_id]
  @any_global_id = params[:any_global_id]

  @options = params 
end

Instance Attribute Details

- (Object) any_global_id

Params specific to AlternateValue



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

def any_global_id
  @any_global_id
end

- (Object) biological_relationship_id

Params specific to AlternateValue



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

def biological_relationship_id
  @biological_relationship_id
end

- (Object) object_global_id

Params specific to AlternateValue



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

def object_global_id
  @object_global_id
end

- (Object) options

General annotator options handling happens directly on the params as passed through to the controller, keep them together here



11
12
13
# File 'lib/queries/biological_association/filter.rb', line 11

def options
  @options
end

- (Object) subject_global_id

Params specific to AlternateValue



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

def subject_global_id
  @subject_global_id
end

Instance Method Details

- (ActiveRecord::Relation) all

Returns:

  • (ActiveRecord::Relation)


89
90
91
92
93
94
95
# File 'lib/queries/biological_association/filter.rb', line 89

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

- (ActiveRecord::Relation) and_clauses

Returns:

  • (ActiveRecord::Relation)


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

def and_clauses
  clauses = [
    matching_subject_global_id, 
    matching_object_global_id,
    matching_any_global_id,
    matching_biological_relationship_id,
  ].compact

  return nil if clauses.empty?

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

- (Object) matching_any_global_id



77
78
79
80
81
# File 'lib/queries/biological_association/filter.rb', line 77

def matching_any_global_id
  t = object_for(any_global_id)
  return nil if t.nil? 
  subject_matches(t).or(object_matches(t))
end

- (Arel::Node?) matching_biological_relationship_id

Returns:

  • (Arel::Node, nil)


84
85
86
# File 'lib/queries/biological_association/filter.rb', line 84

def matching_biological_relationship_id
  biological_relationship_id.blank? ? nil : table[:biological_relationship_id].eq(biological_relationship_id) 
end

- (Object) matching_object_global_id



71
72
73
74
75
# File 'lib/queries/biological_association/filter.rb', line 71

def matching_object_global_id
  t = object_for(object_global_id)
  return nil if t.nil? 
  object_matches(t)
end

- (Object) matching_subject_global_id



65
66
67
68
69
# File 'lib/queries/biological_association/filter.rb', line 65

def matching_subject_global_id
  t = object_for(subject_global_id)
  return nil if t.nil? 
  subject_matches(t)
end

- (ActiveRecord object?) object_for(global_id)

TODO: DRY

Returns:

  • (ActiveRecord object, nil)


45
46
47
48
49
50
51
# File 'lib/queries/biological_association/filter.rb', line 45

def object_for(global_id)
  if o = GlobalID::Locator.locate(global_id) 
    o
  else
    nil
  end
end

- (Object) object_matches(object)



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

def object_matches(object)
  table["biological_association_object_id"].eq(object.id).and(
    table["biological_association_object_type"].eq(object.metamorphosize.class.name) 
  )
end

- (Object) subject_matches(object)



53
54
55
56
57
# File 'lib/queries/biological_association/filter.rb', line 53

def subject_matches(object)
  table["biological_association_subject_id"].eq(object.id).and(
    table["biological_association_subject_type"].eq(object.metamorphosize.class.name) 
  )
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


98
99
100
# File 'lib/queries/biological_association/filter.rb', line 98

def table
  ::BiologicalAssociation.arel_table
end