Sha256: 68f29948c5dbf4952a1c2bf71b2788403027a6f1d7af3493849d31258f04a14c

Contents?: true

Size: 1.33 KB

Versions: 10

Compression:

Stored size: 1.33 KB

Contents

class Quandl::Client::Base
module Validation
  
  extend ActiveSupport::Concern

  included do
  
    before_save :halt_unless_valid!
    
    def valid_with_server?
      return false unless valid?
      return false unless errors_params.blank?
      return false unless errors_server.blank?
      true
    end
    
    def save!
      save
    end
    
    def blank?
      !present?
    end
    
    def exists?
      present?
    end
    
    def present?
      status >= 200 && status < 300
    end
    
    def saved?
      status >= 200 && status <= 210
    end
    
    def queried?
      status > 0
    end
    
    def status
      metadata[:status].to_i
    end
    
    def parse_error
      error_messages[:response_errors].try( :[], :parse_error )
    end
    
    def error_messages
      valid?
      errors_client.deep_merge(errors_server).deep_merge(errors_params)
    end
    
    def errors_client
      errors.messages || {}
    end
    
    def errors_server
      messages = self.attributes[:errors] || {}
      messages[:message] = self.error if self.respond_to?(:error) && self.error.present?
      messages
    end
    
    def errors_params
      response_errors.present? ? { response_errors: response_errors } : {}
    end
    
    protected
  
    def halt_unless_valid!
      return false unless valid?
    end
     
  end
end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
quandl_client-2.2.2 lib/quandl/client/base/validation.rb
quandl_client-2.2.1 lib/quandl/client/base/validation.rb
quandl_client-2.2.0 lib/quandl/client/base/validation.rb
quandl_client-2.1.4 lib/quandl/client/base/validation.rb
quandl_client-2.1.3 lib/quandl/client/base/validation.rb
quandl_client-2.1.2 lib/quandl/client/base/validation.rb
quandl_client-2.1.1 lib/quandl/client/base/validation.rb
quandl_client-2.1.0 lib/quandl/client/base/validation.rb
quandl_client-2.0.1 lib/quandl/client/base/validation.rb
quandl_client-2.0.0 lib/quandl/client/base/validation.rb