class Apicalypse::Scope

Public Class Methods

new(klass) click to toggle source
# File lib/apicalypse/scope.rb, line 3
def initialize(klass)
  @klass = klass
end

Public Instance Methods

chain() click to toggle source
# File lib/apicalypse/scope.rb, line 7
def chain
  @chain ||= {}
end
exclude(*args) click to toggle source
# File lib/apicalypse/scope.rb, line 16
def exclude(*args)
  chain[:exclude] = args.join(',')
  @klass
end
fields(*args) click to toggle source
# File lib/apicalypse/scope.rb, line 11
def fields(*args)
  chain[:fields] = args.join(',')
  @klass
end
limit(args) click to toggle source
# File lib/apicalypse/scope.rb, line 28
def limit(args)
  chain[:limit] = args
  @klass
end
offset(args) click to toggle source
# File lib/apicalypse/scope.rb, line 33
def offset(args)
  chain[:offset] = args
  @klass
end
query(args) click to toggle source
# File lib/apicalypse/scope.rb, line 48
def query(args)
  chain[:query] = args
  @klass
end
sort(args) click to toggle source
# File lib/apicalypse/scope.rb, line 38
def sort(args)
  chain[:sort] = args
  @klass
end
where(args) click to toggle source
# File lib/apicalypse/scope.rb, line 21
def where(args)
  raise_on_invalid_scope_chain(args)

  chain[:where] = chain[:where] ? chain[:where].merge!(args) : args
  @klass
end

Private Instance Methods

raise_on_invalid_scope_chain(scope) click to toggle source
# File lib/apicalypse/scope.rb, line 55
def raise_on_invalid_scope_chain(scope)
  return unless chain[:where]

  if chain[:where].class != scope.class
    raise ScopeError, /Hash and String where scopes can't be combined./
  end
  if chain[:where].is_a?(String)
    raise ScopeError, /Multiple String where scopes are not supported./
  end
end