Class: Attribution
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Attribution
- Includes:
- Housekeeping, Shared::Confidences, Shared::IsData, Shared::Notes, Shared::PolymorphicAnnotator, Shared::Tags
- Defined in:
- app/models/attribution.rb
Overview
An attribution is an explicit assertion of who is responsible for different attributes of the content of tied data.
Constant Summary collapse
- ATTRIBUTION_ROLES =
TODO: Consider DRYing with Source roles.
[ :creator, :editor, :owner, :copyright_holder ]
Instance Attribute Summary collapse
-
#copyright_year ⇒ Integer
4 digit year of copyright.
-
#license ⇒ String
A creative-commons copyright.
Instance Method Summary collapse
- #some_data_provided ⇒ Object protected
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::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Confidences
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#copyright_year ⇒ Integer
Returns 4 digit year of copyright.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
# File 'app/models/attribution.rb', line 11 class Attribution < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Confidences include Shared::Tags include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribution_object') # TODO: Consider DRYing with Source roles. ATTRIBUTION_ROLES = [ :creator, :editor, :owner, :copyright_holder ] ATTRIBUTION_ROLES.each do |r| role_name = "#{r}_roles".to_sym role_person = "attribution_#{r.to_s.pluralize}".to_sym has_many role_name, -> { order('roles.position ASC') }, class_name: "Attribution#{r.to_s.camelize}", as: :role_object, validate: true has_many role_person, -> { order('roles.position ASC') }, through: role_name, source: :person, validate: true accepts_nested_attributes_for role_name, allow_destroy: true accepts_nested_attributes_for role_person end validates_uniqueness_of :attribution_object_id, scope: [:attribution_object_type, :project_id] validates :license, inclusion: {in: CREATIVE_COMMONS_LICENSES.keys}, allow_nil: true validates :copyright_year, date_year: {min_year: 1000, max_year: Time.now.year + 5, message: 'must be an integer greater than 999 and no more than 5 years in the future'} validate :some_data_provided protected def some_data_provided errors.add(:base, 'no attribution metadata') if license.blank? && copyright_year.blank? && !editor_roles.any? && !creator_roles.any? && !owner_roles.any? && !roles.any? end end |
#license ⇒ String
Returns A creative-commons copyright.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
# File 'app/models/attribution.rb', line 11 class Attribution < ApplicationRecord include Housekeeping include Shared::Notes include Shared::Confidences include Shared::Tags include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribution_object') # TODO: Consider DRYing with Source roles. ATTRIBUTION_ROLES = [ :creator, :editor, :owner, :copyright_holder ] ATTRIBUTION_ROLES.each do |r| role_name = "#{r}_roles".to_sym role_person = "attribution_#{r.to_s.pluralize}".to_sym has_many role_name, -> { order('roles.position ASC') }, class_name: "Attribution#{r.to_s.camelize}", as: :role_object, validate: true has_many role_person, -> { order('roles.position ASC') }, through: role_name, source: :person, validate: true accepts_nested_attributes_for role_name, allow_destroy: true accepts_nested_attributes_for role_person end validates_uniqueness_of :attribution_object_id, scope: [:attribution_object_type, :project_id] validates :license, inclusion: {in: CREATIVE_COMMONS_LICENSES.keys}, allow_nil: true validates :copyright_year, date_year: {min_year: 1000, max_year: Time.now.year + 5, message: 'must be an integer greater than 999 and no more than 5 years in the future'} validate :some_data_provided protected def some_data_provided errors.add(:base, 'no attribution metadata') if license.blank? && copyright_year.blank? && !editor_roles.any? && !creator_roles.any? && !owner_roles.any? && !roles.any? end end |
Instance Method Details
#some_data_provided ⇒ Object (protected)
51 52 53 |
# File 'app/models/attribution.rb', line 51 def some_data_provided errors.add(:base, 'no attribution metadata') if license.blank? && copyright_year.blank? && !editor_roles.any? && !creator_roles.any? && !owner_roles.any? && !roles.any? end |