Class: Contracts::ErrorFormatters

Inherits:
Object
  • Object
show all
Defined in:
lib/contracts/error_formatter.rb

Class Method Summary collapse

Class Method Details

.class_for(data) ⇒ Object



10
11
12
13
# File 'lib/contracts/error_formatter.rb', line 10

def self.class_for(data)
  return Contracts::KeywordArgsErrorFormatter if keyword_args?(data)
  DefaultErrorFormatter
end

.failure_msg(data) ⇒ Object

# Given a hash, prints out a failure message. # This function is used by the default #failure_callback method # and uses the hash passed into the failure_callback method.



6
7
8
# File 'lib/contracts/error_formatter.rb', line 6

def self.failure_msg(data)
  class_for(data).new(data).message
end

.keyword_args?(data) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/contracts/error_formatter.rb', line 15

def self.keyword_args?(data)
  data[:contract].is_a?(Contracts::Builtin::KeywordArgs) && data[:arg].is_a?(Hash)
end