Class: RecordLoader::PlateCreatorLoader

Inherits:
ApplicationRecordLoader show all
Defined in:
lib/record_loader/plate_creator_loader.rb

Overview

Schema Information

Table name: plate_creators

id :integer not null, primary key, auto-increment name :string(255) not null valid_options :text utf8mb4, optional (e.g., serialized JSON) created_at :datetime optional updated_at :datetime optional

Notes:

  • Text fields use UTF-8 (utf8mb4) encoding.
  • Timestamps are nullable and can be automatically managed with t.timestamps in migrations.
  • Plate::Creator has a has-many relationship with Plate::Creator::PurposeRelationship and Plate::Creator::ParentPurposeRelationship

Instance Method Summary collapse

Methods inherited from ApplicationRecordLoader

#wip_list

Instance Method Details

#create_or_update!(name, options) ⇒ Plate::Creator

Creates or updates a Plate::Creator record.

If a Plate::Creator with the given name does not exist, it is created and associated with the specified purposes and parent purposes. If it exists, no changes are made.

The base class handles the transaction management, ensuring that the operation is atomic and consistent. If any part of the creation fails, the entire transaction is rolled back.

Parameters:

  • name (String)

    The name of the Plate::Creator.

  • options (Hash)

    Options hash containing purposes and parent_purposes arrays.

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/record_loader/plate_creator_loader.rb', line 33

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#create_plate_creator!(name, options) ⇒ Plate::Creator

Creates a new Plate::Creator and assigns purposes and parent purposes.

Sets valid_options, associates purposes and parent purposes, saves the record, and logs creation. Raises if creation fails.

Parameters:

  • name (String)

    The name of the Plate::Creator.

  • options (Hash)

    Options hash containing purposes, parent_purposes, and valid_options.

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/record_loader/plate_creator_loader.rb', line 65

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#create_plate_creator_if_does_not_exist(name, options) ⇒ Plate::Creator

Finds or creates a Plate::Creator by name.

If a Plate::Creator with the given name exists, logs a warning and returns it. Otherwise, creates a new Plate::Creator with the provided options.

Parameters:

  • name (String)

    The name of the Plate::Creator.

  • options (Hash)

    Options hash containing purposes, parent_purposes, and valid_options.

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/record_loader/plate_creator_loader.rb', line 47

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#parent_purposes(options, plate_creator) ⇒ Array<Plate::Creator::ParentPurposeRelationship>

Parses the parent purposes from the options hash and finds the corresponding PlatePurpose records. If a parent purpose name is not found, it is skipped (returns nil). Plate::Creator::ParentPurposeRelationship objects.

Parameters:

  • options (Hash)

    Options hash expected to contain a 'parent_purposes' array.

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/record_loader/plate_creator_loader.rb', line 97

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#purposes(options, plate_creator) ⇒ Array<Plate::Creator::PurposeRelationship>

Parses the purposes from the options hash and creates corresponding Plate::Creator::PurposeRelationship objects.

Parameters:

  • options (Hash)

    Options hash expected to contain a 'purposes' array.

Returns:

Raises:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/record_loader/plate_creator_loader.rb', line 80

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#valid_options(options) ⇒ Hash

Returns the 'valid_options' value from the options hash as a string.

This method fetches the 'valid_options' key from the provided options hash. If the key is not present, it returns an empty hash. The result is always converted to a hash, ensuring a consistent return type.

Parameters:

  • options (Hash)

    The options hash, expected to possibly contain a 'valid_options' key.

Returns:

  • (Hash)

    The value of 'valid_options' as a hash, or an empty hash if not present.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/record_loader/plate_creator_loader.rb', line 117

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end