Class: MediaTypes::Scheme::ValidationOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/media_types/scheme/validation_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = {}, exhaustive: true, strict: true, backtrace: [], loose: false, expected_key_type:) ⇒ ValidationOptions

Returns a new instance of ValidationOptions.



8
9
10
11
12
13
14
15
# File 'lib/media_types/scheme/validation_options.rb', line 8

def initialize(context = {}, exhaustive: true, strict: true, backtrace: [], loose: false, expected_key_type:)
  self.exhaustive = exhaustive
  self.strict = strict
  self.backtrace = backtrace
  self.context = context
  self.expected_key_type = expected_key_type
  self.loose = loose
end

Instance Attribute Details

#backtraceObject

Returns the value of attribute backtrace.



6
7
8
# File 'lib/media_types/scheme/validation_options.rb', line 6

def backtrace
  @backtrace
end

#contextObject

Returns the value of attribute context.



6
7
8
# File 'lib/media_types/scheme/validation_options.rb', line 6

def context
  @context
end

#exhaustiveObject

Returns the value of attribute exhaustive.



6
7
8
# File 'lib/media_types/scheme/validation_options.rb', line 6

def exhaustive
  @exhaustive
end

#expected_key_typeObject

Returns the value of attribute expected_key_type.



6
7
8
# File 'lib/media_types/scheme/validation_options.rb', line 6

def expected_key_type
  @expected_key_type
end

#looseObject

Returns the value of attribute loose.



6
7
8
# File 'lib/media_types/scheme/validation_options.rb', line 6

def loose
  @loose
end

#strictObject

Returns the value of attribute strict.



6
7
8
# File 'lib/media_types/scheme/validation_options.rb', line 6

def strict
  @strict
end

Instance Method Details

#exhaustive!Object



39
40
41
# File 'lib/media_types/scheme/validation_options.rb', line 39

def exhaustive!
  ValidationOptions.new(context, exhaustive: true, strict: strict, backtrace: backtrace, expected_key_type: expected_key_type, loose: loose)
end

#inspectObject



17
18
19
# File 'lib/media_types/scheme/validation_options.rb', line 17

def inspect
  "backtrack: #{backtrace.inspect}, strict: #{strict.inspect}, loose: #{loose}, exhaustive: #{exhaustive}, current_obj: #{scoped_output.to_json}"
end

#scoped_outputObject



21
22
23
24
25
26
27
28
29
# File 'lib/media_types/scheme/validation_options.rb', line 21

def scoped_output
  current = context

  backtrace.drop(1).first([0, backtrace.size - 2].max).each do |e|
    current = current[e] unless current.nil?
  end

  current
end

#trace(*traces) ⇒ Object



35
36
37
# File 'lib/media_types/scheme/validation_options.rb', line 35

def trace(*traces)
  with_backtrace(backtrace.dup.concat(traces))
end

#with_backtrace(backtrace) ⇒ Object



31
32
33
# File 'lib/media_types/scheme/validation_options.rb', line 31

def with_backtrace(backtrace)
  ValidationOptions.new(context, exhaustive: exhaustive, strict: strict, backtrace: backtrace, expected_key_type: expected_key_type, loose: loose)
end