Class: Documentation

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Housekeeping, Shared::Identifiable, Shared::IsData, Shared::Notable, Shared::Taggable, 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

Constant Summary

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary (collapse)

Class Method 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

- (String) document_id

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
65
# File 'app/models/documentation.rb', line 23

class Documentation < ActiveRecord::Base
  include Housekeeping
  include Shared::Identifiable
  include Shared::Notable
  include Shared::Taggable
  include Shared::IsData
  include SoftValidation


  # 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

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  def self.find_for_autocomplete(params)
    Queries::DocumentationAutocompleteQuery.new(params[:term]).all.where(project_id: params[:project_id])
  end

  protected 


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

end

- (String) documentation_object_id

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
65
# File 'app/models/documentation.rb', line 23

class Documentation < ActiveRecord::Base
  include Housekeeping
  include Shared::Identifiable
  include Shared::Notable
  include Shared::Taggable
  include Shared::IsData
  include SoftValidation


  # 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

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  def self.find_for_autocomplete(params)
    Queries::DocumentationAutocompleteQuery.new(params[:term]).all.where(project_id: params[:project_id])
  end

  protected 


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

end

- (String) documentation_object_type

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
65
# File 'app/models/documentation.rb', line 23

class Documentation < ActiveRecord::Base
  include Housekeeping
  include Shared::Identifiable
  include Shared::Notable
  include Shared::Taggable
  include Shared::IsData
  include SoftValidation


  # 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

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  def self.find_for_autocomplete(params)
    Queries::DocumentationAutocompleteQuery.new(params[:term]).all.where(project_id: params[:project_id])
  end

  protected 


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

end

- (Hash) page_map

Returns maps page numbers, key is Document page, value is Recorded page (e.g. first page of the pdf => published page 10)

Returns:

  • (Hash)

    maps page numbers, key is Document page, value is Recorded page (e.g. first page of the pdf => published page 10)



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
65
# File 'app/models/documentation.rb', line 23

class Documentation < ActiveRecord::Base
  include Housekeeping
  include Shared::Identifiable
  include Shared::Notable
  include Shared::Taggable
  include Shared::IsData
  include SoftValidation


  # 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

  validates_presence_of :document

  accepts_nested_attributes_for :document
  accepts_nested_attributes_for :documentation_object

  def self.find_for_autocomplete(params)
    Queries::DocumentationAutocompleteQuery.new(params[:term]).all.where(project_id: params[:project_id])
  end

  protected 


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

end

Class Method Details

+ (Object) find_for_autocomplete(params)



46
47
48
# File 'app/models/documentation.rb', line 46

def self.find_for_autocomplete(params)
  Queries::DocumentationAutocompleteQuery.new(params[:term]).all.where(project_id: params[:project_id])
end

Instance Method Details

- (Object) catch_statement_invalid (protected)



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

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