Class: Queries::Serial::Filter
- Inherits:
-
Object
- Object
- Queries::Serial::Filter
- Defined in:
- lib/queries/serial/filter.rb
Overview
!! does not inherit from base query
Instance Attribute Summary collapse
-
#name ⇒ Object
Params specific to Note.
-
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here.
Instance Method Summary collapse
- #all ⇒ ActiveRecord::Relation
- #and_clauses ⇒ ActiveRecord::Relation
-
#initialize(params) ⇒ Filter
constructor
A new instance of Filter.
- #matching_name ⇒ Arel::Node?
- #table ⇒ Arel::Table
Constructor Details
#initialize(params) ⇒ Filter
Returns a new instance of Filter.
16 17 18 19 |
# File 'lib/queries/serial/filter.rb', line 16 def initialize(params) @name = params[:name] @options = params end |
Instance Attribute Details
#name ⇒ Object
Params specific to Note
14 15 16 |
# File 'lib/queries/serial/filter.rb', line 14 def name @name end |
#options ⇒ Object
General annotator options handling happens directly on the params as passed through to the controller, keep them together here
11 12 13 |
# File 'lib/queries/serial/filter.rb', line 11 def @options end |
Instance Method Details
#all ⇒ ActiveRecord::Relation
42 43 44 45 46 47 48 |
# File 'lib/queries/serial/filter.rb', line 42 def all if a = and_clauses ::Serial.where(and_clauses.to_sql) else ::Serial.all end end |
#and_clauses ⇒ ActiveRecord::Relation
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/queries/serial/filter.rb', line 22 def and_clauses clauses = [ matching_name, ].compact return nil if clauses.empty? a = clauses.shift clauses.each do |b| a = a.and(b) end a end |
#matching_name ⇒ Arel::Node?
37 38 39 |
# File 'lib/queries/serial/filter.rb', line 37 def matching_name name.blank? ? nil : table[:name].eq(name) end |
#table ⇒ Arel::Table
51 52 53 |
# File 'lib/queries/serial/filter.rb', line 51 def table ::Serial.arel_table end |