Sha256: f8875134f522a018fe0eec7d2e74e3260ee42aba61d8209dc5eb7c36724dceee

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

module Syncano
  class QueryBuilder
    def initialize(connection, resource_class, scope_parameters = {})
      self.connection = connection
      self.resource_class = resource_class
      self.scope_parameters = scope_parameters
    end

    def all(query_params = {})
      query_params[:query] = query_params[:query].to_json if query_params[:query].try(:any?)
      resource_class.all(connection, scope_parameters, query_params)
    end

    def first(query_params = {})
      resource_class.first(connection, scope_parameters, query_params)
    end

    def last(query_params = {})
      resource_class.last(connection, scope_parameters, query_params)
    end

    def find(key = nil)
      resource_class.find(connection, scope_parameters, key)
    end

    def new(attributes = {})
      resource_class.new(connection, scope_parameters, attributes)
    end

    def create(attributes = {})
      resource_class.create(connection, scope_parameters, attributes)
    end

    def destroy(primary_key)
      resource_class.destroy connection, scope_parameters, primary_key
    end

    def space(at, options = {})
      Syncano::Resources::Space.new(at, self, options)
    end

    private

    attr_accessor :connection, :resource_class, :scope_parameters
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
syncano-4.0.0.alpha4 lib/syncano/query_builder.rb
syncano-4.0.0.alpha3 lib/syncano/query_builder.rb
syncano-4.0.0.alpha2 lib/syncano/query_builder.rb
syncano-4.0.0.alpha1 lib/syncano/query_builder.rb