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(pad: 0, itemize: false) ⇒ Object
- #messages_by_path ⇒ Object
- #pad_lines(string, pad = 2) ⇒ 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
56 57 58 59 60 61 62 |
# File 'lib/schemacop/v3/result.rb', line 56 def in_path(segment) prev_path = @current_path @current_path += [segment] yield ensure @current_path = prev_path end |
#messages(pad: 0, itemize: false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/schemacop/v3/result.rb', line 38 def (pad: 0, itemize: false) = [] item_str = itemize ? '- ' : nil @errors.each do |path, | += .map do || pad_lines("#{item_str}/#{path.join('/')}: #{}", pad) 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 |
#pad_lines(string, pad = 2) ⇒ Object
52 53 54 |
# File 'lib/schemacop/v3/result.rb', line 52 def pad_lines(string, pad = 2) string.split("\n").map { |line| "#{' ' * pad}#{line}" }.join("\n") end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/schemacop/v3/result.rb', line 13 def valid? errors.empty? end |