Class: Keyword

Inherits:
ControlledVocabularyTerm show all
Defined in:
app/models/keyword.rb

Direct Known Subclasses

BiocurationGroup

Constant Summary

Constants inherited from ControlledVocabularyTerm

ControlledVocabularyTerm::ALTERNATE_VALUES_FOR

Instance Attribute Summary

Attributes inherited from ControlledVocabularyTerm

#definition, #name, #project_id, #type, #uri, #uri_relation

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ControlledVocabularyTerm

#uri_relation_is_a_skos_relation

Methods included from Housekeeping

#has_polymorphic_relationship?

Class Method Details

.select_optimized(user_id, project_id, klass) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/keyword.rb', line 36

def self.select_optimized(user_id, project_id, klass)
  n = klass.tableize.to_sym
  h = {
    recent: (
      Keyword.where(project_id: project_id, created_by_id: user_id, created_at: 1.day.ago..Time.now)
      .limit(5)
      .order(:name).to_a +
      Keyword.joins(:tags)
      .where(project_id: project_id, tags: {updated_by_id: user_id})
      .used_on_klass(klass)
      .used_recently.limit(5)
      .distinct.to_a ).uniq, 

    pinboard: Keyword.pinned_by(user_id).where(project_id: project_id).to_a
  }

  h[:quick] = (Keyword.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a  + h[:recent][0..3]).uniq
  h
end

.used_recentlyScope

Returns the max 10 most recently used keywords

Returns:

  • (Scope)

    the max 10 most recently used keywords



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/keyword.rb', line 9

def self.used_recently
  t = Tag.arel_table
  k = Keyword.arel_table 

  # i is a select manager
  i = t.project(t['keyword_id'], t['created_at']).from(t)
    .where(t['created_at'].gt( 1.weeks.ago ))
    .order(t['created_at'])
    .take(10)
    .distinct

  # z is a table alias 
  z = i.as('recent_t')

  Keyword.joins(
    Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['keyword_id'].eq(k['id'])))
  )
end

Instance Method Details

#tagged_object_class_namesObject



32
33
34
# File 'app/models/keyword.rb', line 32

def tagged_object_class_names
  tags.pluck(:tag_object_type)
end

#tagged_objectsObject



28
29
30
# File 'app/models/keyword.rb', line 28

def tagged_objects
  tags.collect{|t| t.tag_object}
end