Class: WorkflowTemplate::Definer::HasValidations::Validations::Unprepared

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow_template/definer/has_validations/validations.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(declarations: {}, input_set: nil, output_set: nil) ⇒ Unprepared

Returns a new instance of Unprepared.



43
44
45
46
47
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 43

def initialize(declarations: {}, input_set: nil, output_set: nil)
  @declarations = declarations.freeze
  @input_set = Validations.normalize_entry(input_set)
  @output_set = Validations.normalize_entry(output_set)
end

Instance Attribute Details

#declarationsObject (readonly)

Returns the value of attribute declarations.



41
42
43
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 41

def declarations
  @declarations
end

Class Method Details

.instanceObject



37
38
39
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 37

def self.instance
  new
end

Instance Method Details

#add(declaration) ⇒ Object

Raises:



51
52
53
54
55
56
57
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 51

def add(declaration)
  raise Error, "Declaration name taken: '#{declaration.name}'" if @declarations.key? declaration.name
  raise Error, "Validation '#{declaration.name}' not properly declared" unless valid_declaration?(declaration)

  @declarations = declarations.merge(declaration.name => declaration).freeze
  declaration
end

#freezeObject

Raises:



71
72
73
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 71

def freeze
  raise Error, "Freeze is unimplemented for #{self.class.name}, call #prepared instead"
end

#preparedObject



67
68
69
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 67

def prepared
  Prepared.instance declarations: declarations, input: input_set, output: output_set
end

#validate_input(entry) ⇒ Object



59
60
61
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 59

def validate_input(entry)
  @input_set = Validations.merge_entries(@input_set, entry)
end

#validate_output(entry) ⇒ Object



63
64
65
# File 'lib/workflow_template/definer/has_validations/validations.rb', line 63

def validate_output(entry)
  @output_set = Validations.merge_entries(@output_set, entry)
end