Class: Formalist::Form::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/formalist/form/result.rb,
lib/formalist/form/result/attr.rb,
lib/formalist/form/result/many.rb,
lib/formalist/form/result/field.rb,
lib/formalist/form/result/group.rb,
lib/formalist/form/result/section.rb,
lib/formalist/form/result/component.rb

Defined Under Namespace

Classes: Attr, Component, Field, Group, Many, Section

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, elements, input) ⇒ Result

Returns a new instance of Result.



18
19
20
21
22
23
# File 'lib/formalist/form/result.rb', line 18

def initialize(schema, elements, input)
  @input = input
  @schema = schema
  @elements = elements
  @validation = schema.(input)
end

Instance Attribute Details

#elements ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/formalist/form/result.rb', line 13

def elements
  @elements
end

#input ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
# File 'lib/formalist/form/result.rb', line 7

def input
  @input
end

#schema ⇒ Object (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/formalist/form/result.rb', line 10

def schema
  @schema
end

#validation ⇒ Object (readonly)



16
17
18
# File 'lib/formalist/form/result.rb', line 16

def validation
  @validation
end

Instance Method Details

#messages ⇒ Object



33
34
35
# File 'lib/formalist/form/result.rb', line 33

def messages
  {}
end

#output ⇒ Object



25
26
27
# File 'lib/formalist/form/result.rb', line 25

def output
  validation.output
end

#success? ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/formalist/form/result.rb', line 29

def success?
  true
end

#to_ast ⇒ Object



37
38
39
# File 'lib/formalist/form/result.rb', line 37

def to_ast
  elements.map { |el| el.(output, schema.rules.map(&:to_ary), messages).to_ast }
end

#validate ⇒ Object



41
42
43
# File 'lib/formalist/form/result.rb', line 41

def validate
  ValidatedResult.new(self)
end