Sha256: d899f0abf3388e55e43b20b76c3c9e1b90d2db4da634447f83153ccbcde54321

Contents?: true

Size: 854 Bytes

Versions: 19

Compression:

Stored size: 854 Bytes

Contents

module NCore
  module All
    extend ActiveSupport::Concern

    module ClassMethods
      def all(params={})
        params = parse_request_params(params)
        parsed, creds = request(:get, url, params)
        if parsed[:errors].any?
          raise parent::QueryError, parsed[:errors]
        end
        Collection.new.tap do |coll|
          coll.metadata = parsed[:metadata]
          parsed[:data].each do |hash|
            if key = hash[:object]
              coll << discover_class(key, self).new(hash.merge(metadata: parsed[:metadata]), creds)
            else
              coll << new(hash.merge(metadata: parsed[:metadata]), creds)
            end
          end
        end
      end

      def first(params={})
        params = params.with_indifferent_access.merge(max_results: 1)
        all(params).first
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ncore-2.3.3 lib/ncore/methods/all.rb
ncore-2.3.2 lib/ncore/methods/all.rb
ncore-2.3.1 lib/ncore/methods/all.rb
ncore-2.3.0 lib/ncore/methods/all.rb
ncore-2.2.2 lib/ncore/methods/all.rb
ncore-2.2.1 lib/ncore/methods/all.rb
ncore-2.2.0 lib/ncore/methods/all.rb
ncore-2.1.2 lib/ncore/methods/all.rb
ncore-2.1.1 lib/ncore/methods/all.rb
ncore-2.1.0 lib/ncore/methods/all.rb
ncore-2.0.8 lib/ncore/methods/all.rb
ncore-2.0.7 lib/ncore/methods/all.rb
ncore-2.0.6 lib/ncore/methods/all.rb
ncore-2.0.5 lib/ncore/methods/all.rb
ncore-2.0.4 lib/ncore/methods/all.rb
ncore-2.0.3 lib/ncore/methods/all.rb
ncore-2.0.2 lib/ncore/methods/all.rb
ncore-2.0.1 lib/ncore/methods/all.rb
ncore-2.0.0 lib/ncore/methods/all.rb