Sha256: 2ddd18641bbc49264494e6ad4af4b6973775a2817894af68d66738cd225c595f

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

module Quandl
module Cassinatra
module Concerns
  
module Properties
  extend ActiveSupport::Concern

  included do

    include Her::Model
    use_api Quandl::Cassinatra.her_api
  
    before_save :touch_save_time
    before_save :halt_unless_valid!
    
    after_save :log_save_time
    
    def valid_with_server?
      return false unless valid?
      return false unless errors_params.blank?
      return false unless errors_server.blank?
      true
    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
      self.attributes[:errors] || {}
    end
    
    def errors_params
      response_errors.present? ? { response_errors: response_errors } : {}
    end
    
    
    protected
  
    def halt_unless_valid!
      return false unless valid?
    end
    
    private
    
    def save_timer
      @save_timer
    end
    
    def touch_save_time
      @save_timer = Time.now
    end
    
    def log_save_time
      Quandl::Logger.info("#{self.class.name}.save (#{save_timer.elapsed_ms})")
    end
    
  end      
end

end
end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
quandl_cassinatra-0.1.7 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.1.6 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.1.5 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.1.4 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.1.3 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.1.2 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.1.0 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.15 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.14 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.13 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.12 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.11 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.10 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.9 lib/quandl/cassinatra/concerns/properties.rb
quandl_cassinatra-0.0.8 lib/quandl/cassinatra/concerns/properties.rb