Class: Spyke::NormalizedValidationError

Inherits:
Object
  • Object
show all
Defined in:
lib/spyke/normalized_validation_error.rb

Constant Summary collapse

ERROR_KEY =
:error

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ NormalizedValidationError

Returns a new instance of NormalizedValidationError.



5
6
7
# File 'lib/spyke/normalized_validation_error.rb', line 5

def initialize(attributes)
  @attributes = attributes
end

Instance Method Details

#messageObject



9
10
11
12
13
14
15
16
# File 'lib/spyke/normalized_validation_error.rb', line 9

def message
  case @attributes
  when String
    @attributes
  when Hash
    @attributes[ERROR_KEY].to_sym
  end
end

#optionsObject



18
19
20
21
22
23
24
25
# File 'lib/spyke/normalized_validation_error.rb', line 18

def options
  case @attributes
  when String
    {}
  when Hash
    @attributes.except(ERROR_KEY).symbolize_keys
  end
end