Class: UatActions

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/uat_actions/uat_actions.rb

Overview

Base class for Uat Actions Adding a new action: 1) rails generate uat_action MyNewAction –description=My action description

Author:

  • [jg16]

Defined Under Namespace

Modules: StaticRecords Classes: FormField, GenerateFluidxBarcodes, GeneratePlateConcentrations, GeneratePlates, GeneratePrimerPanel, GenerateProject, GenerateQcResults, GenerateSampleManifest, GenerateSpikedBufferTube, GenerateStudy, GenerateTagGroup, GenerateTagLayoutTemplate, GenerateTagPlates, GenerateTaggedPlates, GenerateTubeRacks, GenerateTubes, IntegrationSuiteTools, PlateInformation, TestSubmission, TubeSubmission

Constant Summary collapse

CATEGORY_LIST =

List of categories to group UatActions by, in the order they should be displayed This is used only for display purposes and can be altered as required

%i[setup_and_test generating_samples auxiliary_data quality_control uncategorised].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allArray<UatAction>

Returns a list of all registered UatActions

Returns:

  • (Array<UatAction>)

    All registered UatActions



26
27
28
# File 'app/uat_actions/uat_actions.rb', line 26

def all
  uat_actions.values
end

.categoryObject

Default category should one not be provided



47
48
49
# File 'app/uat_actions/uat_actions.rb', line 47

def category
  UatActions::CATEGORY_LIST.last
end

.defaultObject



111
112
113
# File 'app/uat_actions/uat_actions.rb', line 111

def default
  new
end

.find(id) ⇒ Class

Find the UatAction identified by the id (Usually the class name parameterized)

Parameters:

  • id (String)

    The id of the UatAction to find.

Returns:

  • (Class)

    A UatAction class



37
38
39
# File 'app/uat_actions/uat_actions.rb', line 37

def find(id)
  uat_actions[id]
end

.form_field(attribute, type, options = {}) ⇒ void

This method returns an undefined value.

Register a new FormField. This will be automatically rendered by the UI and any attributes will be available and instance attributes.

Parameters:

Options Hash (options):

  • :label (String)

    The human readable label for the attribute, determines the field label

  • :help (String)

    More verbose help text to explain the field (shown to the user)

  • :options (Hash)

    Additional options passed through to the ActionView::Helpers::FormBuilder field itself. Eg. required, max, min, include_blank



96
97
98
99
100
101
# File 'app/uat_actions/uat_actions.rb', line 96

def form_field(attribute, type, options = {})
  @form_fields ||= []
  attr_accessor attribute

  @form_fields << UatActions::FormField.new(options.merge(attribute:, type:))
end

.form_fieldsObject



103
104
105
# File 'app/uat_actions/uat_actions.rb', line 103

def form_fields
  @form_fields ||= []
end

.grouped_and_sorted_uat_actionsObject

Returns a hash of all registered uat_actions grouped by category and sorted



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

def grouped_and_sorted_uat_actions
  # raise error if any categories are not in the list
  all.each do |uat_action|
    unless CATEGORY_LIST.include?(uat_action.category)
      raise "Category '#{uat_action.category}' from '#{uat_action}' is not in the list" \
              " of categories #{CATEGORY_LIST}"
    end
  end

  all.group_by(&:category).sort_by { |category, _| CATEGORY_LIST.index(category) }
end

.idObject



77
78
79
# File 'app/uat_actions/uat_actions.rb', line 77

def id
  name.demodulize.parameterize
end

.inherited(other) ⇒ Object

Automatically called by UatActions classes to register themselves

Parameters:

  • other (Class)

    Automatically called when inherited. Receives the descendant class



67
68
69
70
71
# File 'app/uat_actions/uat_actions.rb', line 67

def inherited(other)
  # Register the form_fields of the parent class
  other.form_fields.concat(form_fields)
  UatActions.uat_actions[other.id] = other
end

.permittedObject



107
108
109
# File 'app/uat_actions/uat_actions.rb', line 107

def permitted
  form_fields.map(&:attribute)
end

.to_partial_pathObject



73
74
75
# File 'app/uat_actions/uat_actions.rb', line 73

def to_partial_path
  'uat_actions/entry'
end

.uat_actionsObject

The hash of all registered uat_actions



42
43
44
# File 'app/uat_actions/uat_actions.rb', line 42

def uat_actions
  @uat_actions ||= {}
end

Instance Method Details

#form_fieldsObject



120
121
122
# File 'app/uat_actions/uat_actions.rb', line 120

def form_fields
  self.class.form_fields
end

#performObject



128
129
130
131
# File 'app/uat_actions/uat_actions.rb', line 128

def perform
  errors.add(:base, 'This action has not been implemented.')
  false
end

#reportObject



116
117
118
# File 'app/uat_actions/uat_actions.rb', line 116

def report
  @report ||= {}
end

#saveObject



124
125
126
# File 'app/uat_actions/uat_actions.rb', line 124

def save
  valid? && ActiveRecord::Base.transaction { perform }
end