Class: Repository

Inherits:
ApplicationRecord show all
Includes:
Housekeeping::Timestamps, Housekeeping::Users, Shared::AlternateValues, Shared::Confidences, Shared::DataAttributes, Shared::Identifiers, Shared::IsApplicationData, Shared::IsData, Shared::Notes, Shared::SharedAcrossProjects, Shared::Tags
Defined in:
app/models/repository.rb

Overview

A Repository is a physical location that stores collection objects.

In TaxonWorks, repositories are presently built exclusively at grbio.org/.

Defined Under Namespace

Classes: Autocomplete

Constant Summary collapse

ALTERNATE_VALUES_FOR =
[:name, :acronym]

Instance Attribute Summary collapse

Attributes included from Housekeeping::Users

#by

Class Method Summary collapse

Methods included from Housekeeping::Timestamps

#data_breakdown_for_chartkick_recent

Methods included from Housekeeping::Users

#set_created_by_id, #set_updated_by_id

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#acronymString

Returns a short form name for the repository

Returns:

  • (String)

    a short form name for the repository



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/repository.rb', line 29

class Repository < ApplicationRecord
  include Housekeeping::Users
  include Housekeeping::Timestamps
  include Shared::Notes
  include Shared::SharedAcrossProjects
  include Shared::IsData
  include Shared::IsApplicationData
  include Shared::AlternateValues
  include Shared::DataAttributes
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::Confidences

  ALTERNATE_VALUES_FOR = [:name, :acronym]

  has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error
  validates_presence_of :name, :acronym

  scope :used_in_project, -> (project_id) { joins(:collection_objects).where( collection_objects: { project_id: project_id } ) }

  def self.used_recently(user_id, project_id)
    t = CollectionObject.arel_table
    p = Repository.arel_table

    # i is a select manager
    i = t.project(t['repository_id'], t['created_at']).from(t)
            .where(t['created_at'].gt(1.weeks.ago))
            .where(t['created_by_id'].eq(user_id))
            .where(t['project_id'].eq(project_id))
            .order(t['created_at'].desc)

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

    Repository.joins(
        Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['repository_id'].eq(p['id'])))
    ).pluck(:id).uniq
  end


  def self.select_optimized(user_id, project_id)
    r = used_recently(user_id, project_id)
    h = {
      recent: (Repository.where('"repositories"."id" IN (?)', r.first(10) ).order(:name).to_a +
               Repository.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).to_a).uniq,
    pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a
    }

    h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a +
        Repository.where('"repositories"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
    h
  end

end

#institutional_LSIDString

Returns sensu grbio.org/

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/repository.rb', line 29

class Repository < ApplicationRecord
  include Housekeeping::Users
  include Housekeeping::Timestamps
  include Shared::Notes
  include Shared::SharedAcrossProjects
  include Shared::IsData
  include Shared::IsApplicationData
  include Shared::AlternateValues
  include Shared::DataAttributes
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::Confidences

  ALTERNATE_VALUES_FOR = [:name, :acronym]

  has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error
  validates_presence_of :name, :acronym

  scope :used_in_project, -> (project_id) { joins(:collection_objects).where( collection_objects: { project_id: project_id } ) }

  def self.used_recently(user_id, project_id)
    t = CollectionObject.arel_table
    p = Repository.arel_table

    # i is a select manager
    i = t.project(t['repository_id'], t['created_at']).from(t)
            .where(t['created_at'].gt(1.weeks.ago))
            .where(t['created_by_id'].eq(user_id))
            .where(t['project_id'].eq(project_id))
            .order(t['created_at'].desc)

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

    Repository.joins(
        Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['repository_id'].eq(p['id'])))
    ).pluck(:id).uniq
  end


  def self.select_optimized(user_id, project_id)
    r = used_recently(user_id, project_id)
    h = {
      recent: (Repository.where('"repositories"."id" IN (?)', r.first(10) ).order(:name).to_a +
               Repository.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).to_a).uniq,
    pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a
    }

    h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a +
        Repository.where('"repositories"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
    h
  end

end

#is_index_herbariorumBoolean

Returns see grbio.org/

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/repository.rb', line 29

class Repository < ApplicationRecord
  include Housekeeping::Users
  include Housekeeping::Timestamps
  include Shared::Notes
  include Shared::SharedAcrossProjects
  include Shared::IsData
  include Shared::IsApplicationData
  include Shared::AlternateValues
  include Shared::DataAttributes
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::Confidences

  ALTERNATE_VALUES_FOR = [:name, :acronym]

  has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error
  validates_presence_of :name, :acronym

  scope :used_in_project, -> (project_id) { joins(:collection_objects).where( collection_objects: { project_id: project_id } ) }

  def self.used_recently(user_id, project_id)
    t = CollectionObject.arel_table
    p = Repository.arel_table

    # i is a select manager
    i = t.project(t['repository_id'], t['created_at']).from(t)
            .where(t['created_at'].gt(1.weeks.ago))
            .where(t['created_by_id'].eq(user_id))
            .where(t['project_id'].eq(project_id))
            .order(t['created_at'].desc)

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

    Repository.joins(
        Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['repository_id'].eq(p['id'])))
    ).pluck(:id).uniq
  end


  def self.select_optimized(user_id, project_id)
    r = used_recently(user_id, project_id)
    h = {
      recent: (Repository.where('"repositories"."id" IN (?)', r.first(10) ).order(:name).to_a +
               Repository.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).to_a).uniq,
    pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a
    }

    h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a +
        Repository.where('"repositories"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
    h
  end

end

#nameString

Returns the name of the repository

Returns:

  • (String)

    the name of the repository



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/repository.rb', line 29

class Repository < ApplicationRecord
  include Housekeeping::Users
  include Housekeeping::Timestamps
  include Shared::Notes
  include Shared::SharedAcrossProjects
  include Shared::IsData
  include Shared::IsApplicationData
  include Shared::AlternateValues
  include Shared::DataAttributes
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::Confidences

  ALTERNATE_VALUES_FOR = [:name, :acronym]

  has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error
  validates_presence_of :name, :acronym

  scope :used_in_project, -> (project_id) { joins(:collection_objects).where( collection_objects: { project_id: project_id } ) }

  def self.used_recently(user_id, project_id)
    t = CollectionObject.arel_table
    p = Repository.arel_table

    # i is a select manager
    i = t.project(t['repository_id'], t['created_at']).from(t)
            .where(t['created_at'].gt(1.weeks.ago))
            .where(t['created_by_id'].eq(user_id))
            .where(t['project_id'].eq(project_id))
            .order(t['created_at'].desc)

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

    Repository.joins(
        Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['repository_id'].eq(p['id'])))
    ).pluck(:id).uniq
  end


  def self.select_optimized(user_id, project_id)
    r = used_recently(user_id, project_id)
    h = {
      recent: (Repository.where('"repositories"."id" IN (?)', r.first(10) ).order(:name).to_a +
               Repository.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).to_a).uniq,
    pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a
    }

    h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a +
        Repository.where('"repositories"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
    h
  end

end

#statusString

Returns see grbio.org/

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/repository.rb', line 29

class Repository < ApplicationRecord
  include Housekeeping::Users
  include Housekeeping::Timestamps
  include Shared::Notes
  include Shared::SharedAcrossProjects
  include Shared::IsData
  include Shared::IsApplicationData
  include Shared::AlternateValues
  include Shared::DataAttributes
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::Confidences

  ALTERNATE_VALUES_FOR = [:name, :acronym]

  has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error
  validates_presence_of :name, :acronym

  scope :used_in_project, -> (project_id) { joins(:collection_objects).where( collection_objects: { project_id: project_id } ) }

  def self.used_recently(user_id, project_id)
    t = CollectionObject.arel_table
    p = Repository.arel_table

    # i is a select manager
    i = t.project(t['repository_id'], t['created_at']).from(t)
            .where(t['created_at'].gt(1.weeks.ago))
            .where(t['created_by_id'].eq(user_id))
            .where(t['project_id'].eq(project_id))
            .order(t['created_at'].desc)

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

    Repository.joins(
        Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['repository_id'].eq(p['id'])))
    ).pluck(:id).uniq
  end


  def self.select_optimized(user_id, project_id)
    r = used_recently(user_id, project_id)
    h = {
      recent: (Repository.where('"repositories"."id" IN (?)', r.first(10) ).order(:name).to_a +
               Repository.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).to_a).uniq,
    pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a
    }

    h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a +
        Repository.where('"repositories"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
    h
  end

end

#urlString

Returns see grbio.org/

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/models/repository.rb', line 29

class Repository < ApplicationRecord
  include Housekeeping::Users
  include Housekeeping::Timestamps
  include Shared::Notes
  include Shared::SharedAcrossProjects
  include Shared::IsData
  include Shared::IsApplicationData
  include Shared::AlternateValues
  include Shared::DataAttributes
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::Confidences

  ALTERNATE_VALUES_FOR = [:name, :acronym]

  has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error
  validates_presence_of :name, :acronym

  scope :used_in_project, -> (project_id) { joins(:collection_objects).where( collection_objects: { project_id: project_id } ) }

  def self.used_recently(user_id, project_id)
    t = CollectionObject.arel_table
    p = Repository.arel_table

    # i is a select manager
    i = t.project(t['repository_id'], t['created_at']).from(t)
            .where(t['created_at'].gt(1.weeks.ago))
            .where(t['created_by_id'].eq(user_id))
            .where(t['project_id'].eq(project_id))
            .order(t['created_at'].desc)

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

    Repository.joins(
        Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['repository_id'].eq(p['id'])))
    ).pluck(:id).uniq
  end


  def self.select_optimized(user_id, project_id)
    r = used_recently(user_id, project_id)
    h = {
      recent: (Repository.where('"repositories"."id" IN (?)', r.first(10) ).order(:name).to_a +
               Repository.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).to_a).uniq,
    pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a
    }

    h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a +
        Repository.where('"repositories"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
    h
  end

end

Class Method Details

.select_optimized(user_id, project_id) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/repository.rb', line 70

def self.select_optimized(user_id, project_id)
  r = used_recently(user_id, project_id)
  h = {
    recent: (Repository.where('"repositories"."id" IN (?)', r.first(10) ).order(:name).to_a +
             Repository.where(created_by_id: user_id, created_at: 3.hours.ago..Time.now).limit(5).to_a).uniq,
  pinboard: Repository.pinned_by(user_id).pinned_in_project(project_id).to_a
  }

  h[:quick] = (Repository.pinned_by(user_id).pinboard_inserted.pinned_in_project(project_id).to_a +
      Repository.where('"repositories"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
  h
end

.used_recently(user_id, project_id) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/repository.rb', line 50

def self.used_recently(user_id, project_id)
  t = CollectionObject.arel_table
  p = Repository.arel_table

  # i is a select manager
  i = t.project(t['repository_id'], t['created_at']).from(t)
          .where(t['created_at'].gt(1.weeks.ago))
          .where(t['created_by_id'].eq(user_id))
          .where(t['project_id'].eq(project_id))
          .order(t['created_at'].desc)

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

  Repository.joins(
      Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['repository_id'].eq(p['id'])))
  ).pluck(:id).uniq
end