Module: LHS::Item::Validation

Extended by:
ActiveSupport::Concern
Included in:
LHS::Item
Defined in:
lib/lhs/concerns/item/validation.rb

Instance Method Summary collapse

Instance Method Details

#valid?(options = {}) ⇒ Boolean Also known as: validate

Returns:

  • (Boolean)

10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lhs/concerns/item/validation.rb', line 10

def valid?(options = {})
  options ||= {}
  errors.clear
  endpoint = validation_endpoint
  raise 'No endpoint found to perform validations! See here: https://github.com/local-ch/lhs#validation' unless endpoint
  record = LHS::Record.for_url(endpoint.url)
  params = merge_validation_params!(endpoint).merge options.fetch(:params, {})
  url = validation_url(endpoint)
  run_validation!(record, options, url, params)
  true
rescue LHC::Error => e
  self.errors = LHS::Problems::Errors.new(e.response, record)
  false
end