Module: Pathway::Rspec::FormSchemaHelpers
- Includes:
- FieldListHelpers
- Defined in:
- lib/pathway/rspec/matchers/form_schema_helpers.rb
Instance Method Summary
collapse
#field_list, #pluralize_fields, #were_was
#as_list, #as_sentence
Instance Method Details
#defined ⇒ Object
36
37
38
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 36
def defined
@defined ||= @fields & rules.keys
end
|
#not_defined ⇒ Object
32
33
34
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 32
def not_defined
@not_defined ||= @fields - defined
end
|
#not_defined_list ⇒ Object
12
13
14
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 12
def not_defined_list
"#{as_list(not_defined)} #{were_was(not_defined)} not defined" if not_defined.any?
end
|
#not_optional ⇒ Object
28
29
30
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 28
def not_optional
@not_required ||= defined - optional
end
|
#not_required ⇒ Object
24
25
26
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 24
def not_required
@not_required ||= defined - required
end
|
#optional ⇒ Object
20
21
22
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 20
def optional
@optional ||= @fields.select { |field| optional?(field) }
end
|
#optional?(field) ⇒ Boolean
40
41
42
43
44
45
46
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 40
def optional?(field)
if rules[field]&.type == :implication
left = rules[field].left
left.type == :predicate && left.name == :key? && left.args.first == field
end
end
|
#required ⇒ Object
16
17
18
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 16
def required
@required ||= @fields.select { |field| required?(field) }
end
|
#required?(field) ⇒ Boolean
48
49
50
51
52
53
54
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 48
def required?(field)
if rules[field]&.type == :and
left = rules[field].left
left.type == :predicate && left.name == :key? && left.args.first == field
end
end
|
#rules ⇒ Object
8
9
10
|
# File 'lib/pathway/rspec/matchers/form_schema_helpers.rb', line 8
def rules
@form.rules
end
|