Class: Errapi::ObjectValidator::ContextProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/errapi/object_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, validator, location) ⇒ ContextProxy

Returns a new instance of ContextProxy.



193
194
195
196
197
198
# File 'lib/errapi/object_validator.rb', line 193

def initialize context, validator, location
  @context = context
  @validator = validator
  @current_location = location
  @error_options = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



225
226
227
# File 'lib/errapi/object_validator.rb', line 225

def method_missing name, *args, &block
  @context.send name, *args, &block
end

Instance Attribute Details

#current_locationObject

Returns the value of attribute current_location.



191
192
193
# File 'lib/errapi/object_validator.rb', line 191

def current_location
  @current_location
end

Instance Method Details

#add_error(options = {}, &block) ⇒ Object



200
201
202
# File 'lib/errapi/object_validator.rb', line 200

def add_error options = {}, &block
  @context.add_error @error_options.merge(options), &block
end

#errors?(criteria = {}, &block) ⇒ Boolean

Returns:

  • (Boolean)


204
205
206
207
208
209
210
211
212
# File 'lib/errapi/object_validator.rb', line 204

def errors? criteria = {}, &block

  if criteria[:location].kind_of? RelativeLocation
    criteria = criteria.dup
    criteria[:location] = @current_location.relative criteria[:location].location
  end

  @context.errors? criteria, &block
end

#with_error_options(error_options = {}, &block) ⇒ Object

TODO: override errors? to support matching relative error locations



216
217
218
219
220
221
# File 'lib/errapi/object_validator.rb', line 216

def with_error_options error_options = {}, &block
  previous_error_options = @error_options
  @error_options = error_options
  block.call
  @error_options = previous_error_options
end