Class: Schemacop::Result
- Inherits:
-
Object
- Object
- Schemacop::Result
- Defined in:
- lib/schemacop/v3/result.rb
Instance Attribute Summary collapse
-
#current_path ⇒ Object
readonly
Returns the value of attribute current_path.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #data ⇒ Object
- #error(message) ⇒ Object
- #exception_message ⇒ Object
- #in_path(segment) ⇒ Object
-
#initialize(root = nil, original_data = nil) ⇒ Result
constructor
A new instance of Result.
- #messages ⇒ Object
- #messages_by_path ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
Instance Attribute Details
#current_path ⇒ Object (readonly)
Returns the value of attribute current_path.
3 4 5 |
# File 'lib/schemacop/v3/result.rb', line 3 def current_path @current_path end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/schemacop/v3/result.rb', line 4 def errors @errors end |
Instance Method Details
#data ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/schemacop/v3/result.rb', line 17 def data if errors.any? return nil else return @data ||= @root.cast(@original_data) end end |
#error(message) ⇒ Object
25 26 27 28 |
# File 'lib/schemacop/v3/result.rb', line 25 def error() @errors[current_path] ||= [] @errors[current_path] << end |
#exception_message ⇒ Object
34 35 36 |
# File 'lib/schemacop/v3/result.rb', line 34 def .join("\n") end |
#in_path(segment) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/schemacop/v3/result.rb', line 50 def in_path(segment) prev_path = @current_path @current_path += [segment] yield ensure @current_path = prev_path end |
#messages ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/schemacop/v3/result.rb', line 38 def = [] @errors.each do |path, | += .map do || "/#{path.join('/')}: #{}" end end return end |
#messages_by_path ⇒ Object
30 31 32 |
# File 'lib/schemacop/v3/result.rb', line 30 def @errors.transform_keys { |k| "/#{k.join('/')}" } end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/schemacop/v3/result.rb', line 13 def valid? errors.empty? end |