Class: SchemaTest::Property::Array
- Inherits:
-
SchemaTest::Property
- Object
- SchemaTest::Property
- SchemaTest::Property::Array
- Defined in:
- lib/schema_test/property.rb
Instance Attribute Summary collapse
-
#item_type ⇒ Object
readonly
Returns the value of attribute item_type.
Attributes inherited from SchemaTest::Property
#description, #name, #optional, #type
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json_schema ⇒ Object
- #as_structure(_ = nil) ⇒ Object
-
#initialize(name, of = nil, description = nil, &block) ⇒ Array
constructor
A new instance of Array.
Methods inherited from SchemaTest::Property
#json_schema_format, #json_schema_type, #optional!, #optional?
Constructor Details
#initialize(name, of = nil, description = nil, &block) ⇒ Array
Returns a new instance of Array.
242 243 244 245 246 247 248 249 250 |
# File 'lib/schema_test/property.rb', line 242 def initialize(name, of=nil, description=nil, &block) super(name, :array, description) if block_given? @item_type = AnonymousObject.new(&block) else @item_type = of end # @items = { type: @item_type } end |
Instance Attribute Details
#item_type ⇒ Object (readonly)
Returns the value of attribute item_type.
240 241 242 |
# File 'lib/schema_test/property.rb', line 240 def item_type @item_type end |
Instance Method Details
#==(other) ⇒ Object
252 253 254 |
# File 'lib/schema_test/property.rb', line 252 def ==(other) super && @item_type == other.item_type end |
#as_json_schema ⇒ Object
264 265 266 267 268 269 |
# File 'lib/schema_test/property.rb', line 264 def as_json_schema super.tap do |json_schema| item_schema = @item_type.is_a?(SchemaTest::Property) ? @item_type.as_json_schema(false) : { 'type' => @item_type.to_s } json_schema[name.to_s]['items'] = item_schema end end |
#as_structure(_ = nil) ⇒ Object
256 257 258 259 260 261 262 |
# File 'lib/schema_test/property.rb', line 256 def as_structure(_=nil) if @item_type.is_a?(SchemaTest::Property) { name => @item_type.as_structure(false) } else { name => [] } end end |