Sha256: a9c94af5a1615db632952d73b05e24b8173fc5054202e64266d3cc7e0a2a27c8
Contents?: true
Size: 1.08 KB
Versions: 5
Compression:
Stored size: 1.08 KB
Contents
require 'active_support' class LHS::Item < LHS::Proxy module Validation extend ActiveSupport::Concern def valid? self.errors = nil fail 'No validation endpoint found!' unless validation_endpoint service = LHS::Service.for_url(validation_endpoint.url) params = validation_endpoint.options.fetch(:params, {}).merge(persist: false) begin service.request( url: validation_endpoint.url, method: :post, params: params, body: _data.to_json, headers: {'Content-Type' => 'application/json'} ) true rescue LHC::Error => e self.errors = LHS::Errors.new(e.response) false end end alias_method :validate, :valid? private def validation_endpoint endpoint = _data._service.instance.find_endpoint(_data._raw) endpoint ||= LHS::Endpoint.for_url(_data.href) if _data.href validates = endpoint.options && endpoint.options.fetch(:validates, false) fail 'Endpoint does not support validations!' unless validates endpoint end end end
Version data entries
5 entries across 5 versions & 1 rubygems