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, GeneratePlateConcentrations, GeneratePlates, GeneratePrimerPanel, GenerateTagGroup, GenerateTagLayoutTemplate, GenerateTagPlates, GenerateTaggedPlates, GenerateTubeRacks, IntergrationSuiteTools, PlateInformation, TestSubmission

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


22
23
24
# File 'app/uat_actions/uat_actions.rb', line 22

def all
  uat_actions.values
end

.defaultObject


89
90
91
# File 'app/uat_actions/uat_actions.rb', line 89

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


33
34
35
# File 'app/uat_actions/uat_actions.rb', line 33

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


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

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

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

.form_fieldsObject


81
82
83
# File 'app/uat_actions/uat_actions.rb', line 81

def form_fields
  @form_fields ||= []
end

.idObject


55
56
57
# File 'app/uat_actions/uat_actions.rb', line 55

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


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

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


85
86
87
# File 'app/uat_actions/uat_actions.rb', line 85

def permitted
  form_fields.map(&:attribute)
end

.to_partial_pathObject


51
52
53
# File 'app/uat_actions/uat_actions.rb', line 51

def to_partial_path
  'uat_actions/entry'
end

.uat_actionsObject

The hash of all registered uat_actions


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

def uat_actions
  @uat_actions ||= {}
end

Instance Method Details

#form_fieldsObject


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

def form_fields
  self.class.form_fields
end

#performObject


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

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

#reportObject


94
95
96
# File 'app/uat_actions/uat_actions.rb', line 94

def report
  @report ||= {}
end

#saveObject


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

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