Class: Smith::Workflow::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/workflow/identifier.rb

Class Method Summary collapse

Class Method Details

.normalize(value, label:, allow_nil: false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/smith/workflow/identifier.rb', line 6

def self.normalize(value, label:, allow_nil: false)
  return if value.nil? && allow_nil

  case value
  when String
    raise WorkflowError, "#{label} must not be blank" if value.strip.empty?

    value.dup.freeze
  when Symbol
    raise WorkflowError, "#{label} must not be blank" if value.to_s.empty?

    value
  else
    raise WorkflowError, "#{label} must be a String or Symbol"
  end
end