Class: Repository
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Repository
- Includes:
- Housekeeping::Timestamps, Housekeeping::Users, Shared::AlternateValues, Shared::Confidences, Shared::DataAttributes, Shared::HasPapertrail, 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
-
#acronym ⇒ String
A short form name for the repository.
-
#institutional_LSID ⇒ String
Sensu grbio.org/.
-
#is_index_herbariorum ⇒ Boolean
See grbio.org/.
-
#name ⇒ String
The name of the repository.
-
#status ⇒ String
See grbio.org/.
-
#url ⇒ String
See grbio.org/.
Attributes included from Housekeeping::Users
Class Method Summary collapse
Instance Method Summary collapse
-
#unify_relations ⇒ Object
See serial.rb.
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::HasPapertrail
#attribute_updated, #attribute_updater
Methods included from Shared::Confidences
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uri, #uuid
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
Methods included from Shared::AlternateValues
#all_values_for, #alternate_valued?
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Housekeeping::Users
#set_created_by_id, #set_updated_by_id
Methods inherited from ApplicationRecord
Instance Attribute Details
#acronym ⇒ String
Returns 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/repository.rb', line 29 class Repository < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::Notes include Shared::SharedAcrossProjects include Shared::IsApplicationData include Shared::AlternateValues include Shared::DataAttributes include Shared::Identifiers include Shared::Notes include Shared::Tags include Shared::Confidences include Shared::HasPapertrail include Shared::IsData ALTERNATE_VALUES_FOR = [:name, :acronym] has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error has_many :current_collection_objects, class_name: 'CollectionObject', foreign_key: :current_repository_id, inverse_of: :current_repository, dependent: :restrict_with_error has_many :extracts, 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 } ) } # See serial.rb def unify_relations ApplicationEnumeration.klass_reflections(self.class).select{|a| [ :current_collection_objects, ].include?(a.name) } end 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['updated_at']).from(t) .where(t['updated_at'].gt(4.weeks.ago)) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_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_LSID ⇒ String
Returns sensu grbio.org/.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/repository.rb', line 29 class Repository < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::Notes include Shared::SharedAcrossProjects include Shared::IsApplicationData include Shared::AlternateValues include Shared::DataAttributes include Shared::Identifiers include Shared::Notes include Shared::Tags include Shared::Confidences include Shared::HasPapertrail include Shared::IsData ALTERNATE_VALUES_FOR = [:name, :acronym] has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error has_many :current_collection_objects, class_name: 'CollectionObject', foreign_key: :current_repository_id, inverse_of: :current_repository, dependent: :restrict_with_error has_many :extracts, 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 } ) } # See serial.rb def unify_relations ApplicationEnumeration.klass_reflections(self.class).select{|a| [ :current_collection_objects, ].include?(a.name) } end 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['updated_at']).from(t) .where(t['updated_at'].gt(4.weeks.ago)) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_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_herbariorum ⇒ Boolean
Returns see grbio.org/.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/repository.rb', line 29 class Repository < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::Notes include Shared::SharedAcrossProjects include Shared::IsApplicationData include Shared::AlternateValues include Shared::DataAttributes include Shared::Identifiers include Shared::Notes include Shared::Tags include Shared::Confidences include Shared::HasPapertrail include Shared::IsData ALTERNATE_VALUES_FOR = [:name, :acronym] has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error has_many :current_collection_objects, class_name: 'CollectionObject', foreign_key: :current_repository_id, inverse_of: :current_repository, dependent: :restrict_with_error has_many :extracts, 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 } ) } # See serial.rb def unify_relations ApplicationEnumeration.klass_reflections(self.class).select{|a| [ :current_collection_objects, ].include?(a.name) } end 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['updated_at']).from(t) .where(t['updated_at'].gt(4.weeks.ago)) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_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 |
#name ⇒ String
Returns 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/repository.rb', line 29 class Repository < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::Notes include Shared::SharedAcrossProjects include Shared::IsApplicationData include Shared::AlternateValues include Shared::DataAttributes include Shared::Identifiers include Shared::Notes include Shared::Tags include Shared::Confidences include Shared::HasPapertrail include Shared::IsData ALTERNATE_VALUES_FOR = [:name, :acronym] has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error has_many :current_collection_objects, class_name: 'CollectionObject', foreign_key: :current_repository_id, inverse_of: :current_repository, dependent: :restrict_with_error has_many :extracts, 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 } ) } # See serial.rb def unify_relations ApplicationEnumeration.klass_reflections(self.class).select{|a| [ :current_collection_objects, ].include?(a.name) } end 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['updated_at']).from(t) .where(t['updated_at'].gt(4.weeks.ago)) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_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 |
#status ⇒ String
Returns see grbio.org/.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/repository.rb', line 29 class Repository < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::Notes include Shared::SharedAcrossProjects include Shared::IsApplicationData include Shared::AlternateValues include Shared::DataAttributes include Shared::Identifiers include Shared::Notes include Shared::Tags include Shared::Confidences include Shared::HasPapertrail include Shared::IsData ALTERNATE_VALUES_FOR = [:name, :acronym] has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error has_many :current_collection_objects, class_name: 'CollectionObject', foreign_key: :current_repository_id, inverse_of: :current_repository, dependent: :restrict_with_error has_many :extracts, 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 } ) } # See serial.rb def unify_relations ApplicationEnumeration.klass_reflections(self.class).select{|a| [ :current_collection_objects, ].include?(a.name) } end 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['updated_at']).from(t) .where(t['updated_at'].gt(4.weeks.ago)) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_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 |
#url ⇒ String
Returns see grbio.org/.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/repository.rb', line 29 class Repository < ApplicationRecord include Housekeeping::Users include Housekeeping::Timestamps include Shared::Notes include Shared::SharedAcrossProjects include Shared::IsApplicationData include Shared::AlternateValues include Shared::DataAttributes include Shared::Identifiers include Shared::Notes include Shared::Tags include Shared::Confidences include Shared::HasPapertrail include Shared::IsData ALTERNATE_VALUES_FOR = [:name, :acronym] has_many :collection_objects, inverse_of: :repository, dependent: :restrict_with_error has_many :current_collection_objects, class_name: 'CollectionObject', foreign_key: :current_repository_id, inverse_of: :current_repository, dependent: :restrict_with_error has_many :extracts, 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 } ) } # See serial.rb def unify_relations ApplicationEnumeration.klass_reflections(self.class).select{|a| [ :current_collection_objects, ].include?(a.name) } end 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['updated_at']).from(t) .where(t['updated_at'].gt(4.weeks.ago)) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_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
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/repository.rb', line 85 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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/repository.rb', line 65 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['updated_at']).from(t) .where(t['updated_at'].gt(4.weeks.ago)) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_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 |
Instance Method Details
#unify_relations ⇒ Object
See serial.rb
56 57 58 59 60 61 |
# File 'app/models/repository.rb', line 56 def unify_relations ApplicationEnumeration.klass_reflections(self.class).select{|a| [ :current_collection_objects, ].include?(a.name) } end |