Sha256: d70f6e6bd0e8ebf9374c9aa97e8f1a013100e2c3d0c7cb397879c4c2763bba5e
Contents?: true
Size: 1.21 KB
Versions: 11
Compression:
Stored size: 1.21 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 record = LHS::Record.for_url(validation_endpoint.url) validation_params = validation_endpoint.options[:validates] == true ? { persist: false } : { validation_endpoint.options[:validates] => false } params = validation_endpoint.options.fetch(:params, {}).merge(validation_params) begin record.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 validate valid? private def validation_endpoint endpoint = _data._record.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
11 entries across 11 versions & 1 rubygems