class Mailroute::Relation

Attributes

search_options[R]

Public Class Methods

new(klass, search_options = {}) click to toggle source
# File lib/mailroute/extensions/relation.rb, line 9
def initialize(klass, search_options = {})
  @klass = klass
  @search_options = search_options
end

Public Instance Methods

==(other) click to toggle source
# File lib/mailroute/extensions/relation.rb, line 38
def ==(other)
  case other
  when Relation
    search_options == other.search_options
  when Array
    to_a == other
  else
    false
  end
end
filter(options) click to toggle source
# File lib/mailroute/extensions/relation.rb, line 26
def filter(options)
  new_relation(:params => options)
end
limit(n) click to toggle source
# File lib/mailroute/extensions/relation.rb, line 18
def limit(n)
  new_relation(:params => { :limit => n })
end
offset(n) click to toggle source
# File lib/mailroute/extensions/relation.rb, line 22
def offset(n)
  new_relation(:params => { :offset => n })
end
order_by(attribute) click to toggle source
# File lib/mailroute/extensions/relation.rb, line 30
def order_by(attribute)
  new_relation(:params => { :order_by => attribute })
end
to_a() click to toggle source
# File lib/mailroute/extensions/relation.rb, line 14
def to_a
  @records ||= @klass.all(search_options)
end
total_count() click to toggle source
# File lib/mailroute/extensions/relation.rb, line 49
def total_count
  meta = to_a.instance_variable_get(:@_meta)
  meta && meta['total_count']
end

Private Instance Methods

new_relation(options_update) click to toggle source
# File lib/mailroute/extensions/relation.rb, line 56
def new_relation(options_update)
  Mailroute::Relation.new(@klass, search_options.deep_merge(options_update))
end