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: []) ⇒ ValidationOptions

Returns a new instance of ValidationOptions.



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

def initialize(context = {}, exhaustive: true, strict: true, backtrace: [])
  self.exhaustive = exhaustive
  self.strict = strict
  self.backtrace = backtrace
  self.context = context
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

#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



37
38
39
# File 'lib/media_types/scheme/validation_options.rb', line 37

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

#inspectObject



15
16
17
# File 'lib/media_types/scheme/validation_options.rb', line 15

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

#scoped_outputObject



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

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



33
34
35
# File 'lib/media_types/scheme/validation_options.rb', line 33

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

#with_backtrace(backtrace) ⇒ Object



29
30
31
# File 'lib/media_types/scheme/validation_options.rb', line 29

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