Class: Attribution

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Confidences, Shared::HasRoles, 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

ATTRIBUTION_ROLES =

TODO: Consider DRYing with Source roles.

[
  :creator,
  :editor,
  :owner,
  :copyright_holder
]

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

Returns 4 digit year of copyright

Returns:

  • (Integer)

    4 digit year of copyright



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
56
57
# File 'app/models/attribution.rb', line 12

class Attribution < ApplicationRecord
  include Housekeeping
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  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?
  end

end

- (String) license

Returns A creative-commons copyright

Returns:

  • (String)

    A creative-commons copyright



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
56
57
# File 'app/models/attribution.rb', line 12

class Attribution < ApplicationRecord
  include Housekeeping
  include Shared::Notes
  include Shared::Confidences
  include Shared::HasRoles
  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?
  end

end

Instance Method Details

- (Object) some_data_provided (protected)



53
54
55
# File 'app/models/attribution.rb', line 53

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?
end