Class: Shale::Schema::JSONGenerator::Base Private
- Inherits:
-
Object
- Object
- Shale::Schema::JSONGenerator::Base
- Defined in:
- lib/shale/schema/json_generator/base.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base class for JSON Schema types
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
private
Return name.
-
#nullable ⇒ Object
writeonly
private
Set nullable.
-
#schema ⇒ Object
readonly
private
Return schema hash.
Instance Method Summary collapse
-
#as_json ⇒ Hash
private
Return JSON Schema fragment as Ruby Hash.
-
#initialize(name, default: nil, schema: nil) ⇒ Base
constructor
private
A new instance of Base.
Constructor Details
#initialize(name, default: nil, schema: nil) ⇒ Base
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.
Returns a new instance of Base.
25 26 27 28 29 30 |
# File 'lib/shale/schema/json_generator/base.rb', line 25 def initialize(name, default: nil, schema: nil) @name = name.gsub('::', '_') @default = default @schema = schema || {} @nullable = !schema&.[](:required) end |
Instance Attribute Details
#name ⇒ 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.
Return name
13 14 15 |
# File 'lib/shale/schema/json_generator/base.rb', line 13 def name @name end |
#nullable=(value) ⇒ Object (writeonly)
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.
Set nullable
23 24 25 |
# File 'lib/shale/schema/json_generator/base.rb', line 23 def nullable=(value) @nullable = value 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.
Return schema hash
18 19 20 |
# File 'lib/shale/schema/json_generator/base.rb', line 18 def schema @schema end |
Instance Method Details
#as_json ⇒ Hash
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.
Return JSON Schema fragment as Ruby Hash
37 38 39 40 41 42 43 |
# File 'lib/shale/schema/json_generator/base.rb', line 37 def as_json type = as_type type['type'] = [*type['type'], 'null'] if type['type'] && @nullable type['default'] = @default unless @default.nil? type end |