Class: Mailroute::Relation
- Includes:
- Enumerable
- Defined in:
- lib/mailroute/extensions/relation.rb
Instance Attribute Summary collapse
-
#search_options ⇒ Object
readonly
Returns the value of attribute search_options.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #filter(options) ⇒ Object
-
#initialize(klass, search_options = {}) ⇒ Relation
constructor
A new instance of Relation.
- #limit(n) ⇒ Object
- #offset(n) ⇒ Object
- #order_by(attribute) ⇒ Object
- #search(term) ⇒ Object
- #to_a ⇒ Object
- #total_count ⇒ Object
Constructor Details
#initialize(klass, search_options = {}) ⇒ Relation
Returns a new instance of Relation.
9 10 11 12 |
# File 'lib/mailroute/extensions/relation.rb', line 9 def initialize(klass, = {}) @klass = klass @search_options = end |
Instance Attribute Details
#search_options ⇒ Object (readonly)
Returns the value of attribute search_options.
7 8 9 |
# File 'lib/mailroute/extensions/relation.rb', line 7 def @search_options end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mailroute/extensions/relation.rb', line 38 def ==(other) case other when Relation == other. when Array to_a == other else false end end |
#filter(options) ⇒ Object
26 27 28 |
# File 'lib/mailroute/extensions/relation.rb', line 26 def filter() new_relation(:params => ) end |
#limit(n) ⇒ Object
18 19 20 |
# File 'lib/mailroute/extensions/relation.rb', line 18 def limit(n) new_relation(:params => { :limit => n }) end |
#offset(n) ⇒ Object
22 23 24 |
# File 'lib/mailroute/extensions/relation.rb', line 22 def offset(n) new_relation(:params => { :offset => n }) end |
#order_by(attribute) ⇒ Object
30 31 32 |
# File 'lib/mailroute/extensions/relation.rb', line 30 def order_by(attribute) new_relation(:params => { :order_by => attribute }) end |
#search(term) ⇒ Object
34 35 36 |
# File 'lib/mailroute/extensions/relation.rb', line 34 def search(term) new_relation(:params => { :q => term }) end |
#to_a ⇒ Object
14 15 16 |
# File 'lib/mailroute/extensions/relation.rb', line 14 def to_a @records ||= @klass.all() end |
#total_count ⇒ Object
49 50 51 52 |
# File 'lib/mailroute/extensions/relation.rb', line 49 def total_count = to_a.instance_variable_get(:@_meta) && ['total_count'] end |