Sha256: dfee6aa79775aefdf830878291e0b8c9650dbf4a91284f4083a26afdfdccd335

Contents?: true

Size: 1.07 KB

Versions: 23

Compression:

Stored size: 1.07 KB

Contents

class Quandl::Client::Base
module Search
  
  extend ActiveSupport::Concern
  
  module ClassMethods
    def forwardable_scope_methods
      @forwardable_scope_methods ||= Array.forwardable_methods.reject{|m| [:find, :fetch].include?(m) }
    end
  end
  
  included do

    include ScopeComposer::Model

    has_scope_composer

    scope :with_id,      ->(value)   { where( id: value.to_i )}
    scope_helper :all, ->{ connection.where(attributes_with_scopes).fetch }
    scope_helper :connection, -> { self.class.parent }
    
    scope.class_eval do

      delegate *Array.forwardable_methods.reject{|m| [:find, :fetch].include?(m) }, to: :all
      
      def fetch_once
        @fetch_once ||= fetch
      end
    
      def fetch
        find(attributes_with_scopes[:id])
      end
    
      def find(id)
        result = self.class.parent.where( attributes_with_scopes ).find(id)
        result = self.class.parent.new(id: id) if result.nil?
        result
      end
      
      def attributes_with_scopes
        attributes.merge(scope_attributes)
      end
      
    end
  
  end
end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
quandl_client-2.6.2 lib/quandl/client/base/search.rb
quandl_client-2.6.1 lib/quandl/client/base/search.rb
quandl_client-2.6.0 lib/quandl/client/base/search.rb
quandl_client-2.5.3 lib/quandl/client/base/search.rb
quandl_client-2.5.2 lib/quandl/client/base/search.rb
quandl_client-2.5.1 lib/quandl/client/base/search.rb
quandl_client-2.5.0 lib/quandl/client/base/search.rb
quandl_client-2.4.9 lib/quandl/client/base/search.rb
quandl_client-2.4.8 lib/quandl/client/base/search.rb
quandl_client-2.4.7 lib/quandl/client/base/search.rb
quandl_client-2.4.6 lib/quandl/client/base/search.rb
quandl_client-2.4.5 lib/quandl/client/base/search.rb
quandl_client-2.4.4 lib/quandl/client/base/search.rb
quandl_client-2.4.3 lib/quandl/client/base/search.rb
quandl_client-2.4.2 lib/quandl/client/base/search.rb
quandl_client-2.4.1 lib/quandl/client/base/search.rb
quandl_client-2.4.0 lib/quandl/client/base/search.rb
quandl_client-2.3.2 lib/quandl/client/base/search.rb
quandl_client-2.3.1 lib/quandl/client/base/search.rb
quandl_client-2.3.0 lib/quandl/client/base/search.rb