class FQuery

Public Instance Methods

end_at(priority) click to toggle source
# File lib/firebase/fquery.rb, line 81
def end_at(priority)
  queryEndingAtPriority(priority)
end
equal_to(priority) click to toggle source
# File lib/firebase/fquery.rb, line 73
def equal_to(priority)
  queryEqualToPriority(priority)
end
limit(limit) click to toggle source
# File lib/firebase/fquery.rb, line 89
def limit(limit)
  queryLimitedToNumberOfChildren(limit)
end
name() click to toggle source

previously the ‘key’ method was called ‘name’

# File lib/firebase/fquery.rb, line 4
def name
  self.key
end
off(handle=nil) click to toggle source
# File lib/firebase/fquery.rb, line 56
def off(handle=nil)
  if handle
    removeObserverWithHandle(handle)
  else
    removeAllObservers
  end
  return self
end
on(event_type, options={}, &and_then) click to toggle source
# File lib/firebase/fquery.rb, line 8
def on(event_type, options={}, &and_then)
  and_then = and_then || options[:completion]
  raise "event handler is required" unless and_then
  raise "event handler must accept one or two arguments" unless and_then.arity == 1 || and_then.arity == 2

  event_type = Firebase.convert_event_type(event_type)
  disconnect_block = options[:disconnect]
  raise ":disconnect handler must not accept any arguments" if disconnect_block && disconnect_block.arity > 0

  if and_then.arity == 1
    if disconnect_block
      return observeEventType(event_type, withBlock:and_then, withCancelBlock:disconnect_block)
    else
      return observeEventType(event_type, withBlock:and_then)
    end
  else
    if disconnect_block
      return observeEventType(event_type, andPreviousSiblingNameWithBlock:and_then, withCancelBlock:disconnect_block)
    else
      return observeEventType(event_type, andPreviousSiblingNameWithBlock:and_then)
    end
  end
end
once(event_type, options={}, &and_then) click to toggle source
# File lib/firebase/fquery.rb, line 32
def once(event_type, options={}, &and_then)
  and_then = and_then || options[:completion]
  raise "event handler is required" unless and_then
  raise "event handler must accept one or two arguments" unless and_then.arity == 1 || and_then.arity == 2

  event_type = Firebase.convert_event_type(event_type)
  disconnect_block = options[:disconnect]
  raise ":disconnect handler must not accept any arguments" if disconnect_block && disconnect_block.arity > 0

  if and_then.arity == 1
    if disconnect_block
      return observeSingleEventOfType(event_type, withBlock:and_then, withCancelBlock:disconnect_block)
    else
      return observeSingleEventOfType(event_type, withBlock:and_then)
    end
  else
    if disconnect_block
      return observeSingleEventOfType(event_type, andPreviousSiblingNameWithBlock:and_then, withCancelBlock:disconnect_block)
    else
      return observeSingleEventOfType(event_type, andPreviousSiblingNameWithBlock:and_then)
    end
  end
end
query(options={}, &block) click to toggle source
# File lib/firebase/fquery.rb, line 93
def query(options={}, &block)
  fb_query = self

  if options[:order_by_key]
    fb_query = fb_query.queryOrderedByKey
  end

  if options[:order_by_priority]
    fb_query = fb_query.queryOrderedByPriority
  end

  if options[:order_by]
    fb_query = fb_query.queryOrderedByChild(options[:order_by])
  end

  if options[:first]
    fb_query = fb_query.queryLimitedToFirst(options[:first])
  end

  if options[:last]
    fb_query = fb_query.queryLimitedToLast(options[:last])
  end

  if options[:starting_at] && options[:key]
    fb_query = fb_query.queryStartingAtValue(options[:starting_at], childKey: options[:key])
  elsif options[:starting_at]
    fb_query = fb_query.queryStartingAtValue(options[:starting_at])
  end

  if options[:ending_at] && options[:key]
    fb_query = fb_query.queryEndingAtValue(options[:ending_at], childKey: options[:key])
  elsif options[:ending_at]
    fb_query = fb_query.queryEndingAtValue(options[:ending_at])
  end

  if options[:equal_to] && options[:key]
    fb_query = fb_query.queryEqualToValue(options[:equal_to], childKey: options[:key])
  elsif options[:equal_to]
    fb_query = fb_query.queryEqualToValue(options[:equal_to])
  end

  if block
    event_type = options.fetch(:once, options.fetch(:on, FEventTypeValue))
    event_type = Firebase.convert_event_type(event_type)

    if options.key?(:once)
      return fb_query.observeSingleEventOfType(event_type, withBlock: block)
    else
      return fb_query.observeEventType(event_type, withBlock: block)
    end
  else
    fb_query
  end
end
start_at(priority) click to toggle source
# File lib/firebase/fquery.rb, line 65
def start_at(priority)
  queryStartingAtPriority(priority)
end