Class: Halidator
- Inherits:
-
Object
- Object
- Halidator
- Defined in:
- lib/halidator.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #debug(*str) ⇒ Object
-
#initialize(hal, engine = :pure_ruby) ⇒ Halidator
constructor
A new instance of Halidator.
- #parse_json ⇒ Object
- #show_errors ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(hal, engine = :pure_ruby) ⇒ Halidator
Returns a new instance of Halidator.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/halidator.rb', line 7 def initialize(hal, engine = :pure_ruby) case hal when String @json_string = hal parse_json else @json = hal end @errors = [] if engine == :json_schema extend Halidate::JsonSchema else extend Halidate::PureRuby end end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
6 7 8 |
# File 'lib/halidator.rb', line 6 def errors @errors end |
Instance Method Details
#debug(*str) ⇒ Object
33 34 35 36 37 |
# File 'lib/halidator.rb', line 33 def debug(*str) if $DEBUG $stderr.puts str end end |
#parse_json ⇒ Object
23 24 25 |
# File 'lib/halidator.rb', line 23 def parse_json @json = JSON.parse(@json_string) end |
#show_errors ⇒ Object
39 40 41 42 43 |
# File 'lib/halidator.rb', line 39 def show_errors debug ["\nERRORS-VVVVVVVVVVVVVVVVVV", *errors, "ERRORS-^^^^^^^^^^^^^^^^^^"] end |
#valid? ⇒ Boolean
27 28 29 30 31 |
# File 'lib/halidator.rb', line 27 def valid? result = validate_json_as_hal show_errors result end |