Class: Documentation

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Identifiers, Shared::IsData, Shared::Notes, Shared::PolymorphicAnnotator, Shared::Tags, SoftValidation
Defined in:
app/models/documentation.rb

Overview

A Documentation instance describes the relationship between a digital document (e.g pdf, txt file) and some data instance. Data types that can be document use Shared::Documentation.

Documentation is to Documents as Depictions are to Images. !!`Documentation` is both singular and plural!!

Constant Summary

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SoftValidation

#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Attribute Details

#document_idString

Returns the id of the Document

Returns:

  • (String)

    the id of the Document



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
58
59
60
61
62
63
64
# File 'app/models/documentation.rb', line 23

class Documentation < ApplicationRecord

  acts_as_list scope: [:project_id, :documentation_object_id, :documentation_object_type]

  include Housekeeping
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::IsData
  include SoftValidation
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:documentation_object)

  # These are all handled on the database side as not-null constraints
  # They can't be validated because we use accepts_nested_attributes
  # validates_presence_of :documentation_object_type, :documentation_object_id, :document_id
  # We catch invalid statements with this around:
  around_save :catch_statement_invalid

  belongs_to :documentation_object, polymorphic: true
  belongs_to :document, inverse_of: :documentation

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  protected

  def catch_statement_invalid
    begin
      yield # calls :after_save callback
    rescue ActiveRecord::StatementInvalid => e
      if e.cause.class.name == 'PG::NotNullViolation'
        errors.add(:base, 'a required field was not provided')
      else
        raise
      end
    end
  end

end

#documentation_object_idString

Returns the id of the documented object

Returns:

  • (String)

    the id of the documented object



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
58
59
60
61
62
63
64
# File 'app/models/documentation.rb', line 23

class Documentation < ApplicationRecord

  acts_as_list scope: [:project_id, :documentation_object_id, :documentation_object_type]

  include Housekeeping
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::IsData
  include SoftValidation
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:documentation_object)

  # These are all handled on the database side as not-null constraints
  # They can't be validated because we use accepts_nested_attributes
  # validates_presence_of :documentation_object_type, :documentation_object_id, :document_id
  # We catch invalid statements with this around:
  around_save :catch_statement_invalid

  belongs_to :documentation_object, polymorphic: true
  belongs_to :document, inverse_of: :documentation

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  protected

  def catch_statement_invalid
    begin
      yield # calls :after_save callback
    rescue ActiveRecord::StatementInvalid => e
      if e.cause.class.name == 'PG::NotNullViolation'
        errors.add(:base, 'a required field was not provided')
      else
        raise
      end
    end
  end

end

#documentation_object_typeString

Returns the type of the documented object

Returns:

  • (String)

    the type of the documented object



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
58
59
60
61
62
63
64
# File 'app/models/documentation.rb', line 23

class Documentation < ApplicationRecord

  acts_as_list scope: [:project_id, :documentation_object_id, :documentation_object_type]

  include Housekeeping
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::IsData
  include SoftValidation
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:documentation_object)

  # These are all handled on the database side as not-null constraints
  # They can't be validated because we use accepts_nested_attributes
  # validates_presence_of :documentation_object_type, :documentation_object_id, :document_id
  # We catch invalid statements with this around:
  around_save :catch_statement_invalid

  belongs_to :documentation_object, polymorphic: true
  belongs_to :document, inverse_of: :documentation

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  protected

  def catch_statement_invalid
    begin
      yield # calls :after_save callback
    rescue ActiveRecord::StatementInvalid => e
      if e.cause.class.name == 'PG::NotNullViolation'
        errors.add(:base, 'a required field was not provided')
      else
        raise
      end
    end
  end

end

#positionInteger

Returns for acts as list, scopes to document

Returns:

  • (Integer)

    for acts as list, scopes to document



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
58
59
60
61
62
63
64
# File 'app/models/documentation.rb', line 23

class Documentation < ApplicationRecord

  acts_as_list scope: [:project_id, :documentation_object_id, :documentation_object_type]

  include Housekeeping
  include Shared::Identifiers
  include Shared::Notes
  include Shared::Tags
  include Shared::IsData
  include SoftValidation
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:documentation_object)

  # These are all handled on the database side as not-null constraints
  # They can't be validated because we use accepts_nested_attributes
  # validates_presence_of :documentation_object_type, :documentation_object_id, :document_id
  # We catch invalid statements with this around:
  around_save :catch_statement_invalid

  belongs_to :documentation_object, polymorphic: true
  belongs_to :document, inverse_of: :documentation

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  protected

  def catch_statement_invalid
    begin
      yield # calls :after_save callback
    rescue ActiveRecord::StatementInvalid => e
      if e.cause.class.name == 'PG::NotNullViolation'
        errors.add(:base, 'a required field was not provided')
      else
        raise
      end
    end
  end

end

Instance Method Details

#catch_statement_invalidObject (protected)



52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/documentation.rb', line 52

def catch_statement_invalid
  begin
    yield # calls :after_save callback
  rescue ActiveRecord::StatementInvalid => e
    if e.cause.class.name == 'PG::NotNullViolation'
      errors.add(:base, 'a required field was not provided')
    else
      raise
    end
  end
end