Class: Schemacop::V3::Context
- Inherits:
-
Object
- Object
- Schemacop::V3::Context
- Defined in:
- lib/schemacop/v3/context.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_JSON_FORMAT =
:default
Instance Attribute Summary collapse
-
#json_format ⇒ Object
Returns the value of attribute json_format.
-
#schemas ⇒ Object
Returns the value of attribute schemas.
Instance Method Summary collapse
-
#initialize(json_format: DEFAULT_JSON_FORMAT) ⇒ Context
constructor
A new instance of Context.
- #schema(name, type = :hash, **options, &block) ⇒ Object
- #swagger_json? ⇒ Boolean
- #with_json_format(json_format) ⇒ Object
Constructor Details
#initialize(json_format: DEFAULT_JSON_FORMAT) ⇒ Context
Returns a new instance of Context.
9 10 11 12 |
# File 'lib/schemacop/v3/context.rb', line 9 def initialize(json_format: DEFAULT_JSON_FORMAT) @schemas = {}.with_indifferent_access.freeze @json_format = json_format end |
Instance Attribute Details
#json_format ⇒ Object
Returns the value of attribute json_format.
5 6 7 |
# File 'lib/schemacop/v3/context.rb', line 5 def json_format @json_format end |
#schemas ⇒ Object
Returns the value of attribute schemas.
4 5 6 |
# File 'lib/schemacop/v3/context.rb', line 4 def schemas @schemas end |
Instance Method Details
#schema(name, type = :hash, **options, &block) ⇒ Object
14 15 16 17 18 |
# File 'lib/schemacop/v3/context.rb', line 14 def schema(name, type = :hash, **, &block) @schemas = @schemas.merge( name => Node.create(type, **, &block) ).freeze end |
#swagger_json? ⇒ Boolean
28 29 30 |
# File 'lib/schemacop/v3/context.rb', line 28 def swagger_json? @json_format == :swagger end |
#with_json_format(json_format) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/schemacop/v3/context.rb', line 20 def with_json_format(json_format) prev_json_format = @json_format @json_format = json_format return yield ensure @json_format = prev_json_format end |