Class: Schemacop::V3::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/schemacop/v3/context.rb

Direct Known Subclasses

GlobalContext

Constant Summary collapse

DEFAULT_JSON_FORMAT =
:default

Instance Attribute Summary collapse

Instance Method Summary collapse

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_formatObject

Returns the value of attribute json_format.



5
6
7
# File 'lib/schemacop/v3/context.rb', line 5

def json_format
  @json_format
end

#schemasObject

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, **options, &block)
  @schemas = @schemas.merge(
    name => Node.create(type, **options, &block)
  ).freeze
end

#swagger_json?Boolean

Returns:

  • (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