Class: ApiTester::ArrayField
- Defined in:
- lib/api-tester/definition/fields/array_field.rb
Overview
Class used for defining array fields
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
Attributes inherited from Field
#has_key, #is_seen, #name, #required
Instance Method Summary collapse
- #default ⇒ Object
-
#initialize(name:, required: false, has_key: true) ⇒ ArrayField
constructor
A new instance of ArrayField.
- #negative_boundary_values ⇒ Object
- #subfields? ⇒ Boolean
- #type ⇒ Object
- #with_field(new_field) ⇒ Object
Methods inherited from Field
#display_class, #good_cases, #is_not_required, #is_required, #seen
Constructor Details
#initialize(name:, required: false, has_key: true) ⇒ ArrayField
Returns a new instance of ArrayField.
10 11 12 13 |
# File 'lib/api-tester/definition/fields/array_field.rb', line 10 def initialize(name:, required: false, has_key: true) super name: name, required: required, has_key: has_key self.fields = [] end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
8 9 10 |
# File 'lib/api-tester/definition/fields/array_field.rb', line 8 def fields @fields end |
Instance Method Details
#default ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/api-tester/definition/fields/array_field.rb', line 28 def default return [] if fields.size.zero? obj = {} fields.each do |field| obj[field.name] = field.default end [obj] end |
#negative_boundary_values ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/api-tester/definition/fields/array_field.rb', line 38 def negative_boundary_values super + [ 'string', 123, 0, 1, true, false, {} ] end |
#subfields? ⇒ Boolean
20 21 22 |
# File 'lib/api-tester/definition/fields/array_field.rb', line 20 def subfields? true end |
#type ⇒ Object
24 25 26 |
# File 'lib/api-tester/definition/fields/array_field.rb', line 24 def type 'array' end |
#with_field(new_field) ⇒ Object
15 16 17 18 |
# File 'lib/api-tester/definition/fields/array_field.rb', line 15 def with_field(new_field) fields << new_field self end |