Class: NQL::Query
- Inherits:
-
Object
- Object
- NQL::Query
- Defined in:
- lib/nql/query.rb
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(model, text) ⇒ Query
constructor
A new instance of Query.
- #ransack_search ⇒ Object
Constructor Details
#initialize(model, text) ⇒ Query
Returns a new instance of Query.
8 9 10 11 12 13 14 |
# File 'lib/nql/query.rb', line 8 def initialize(model, text) raise InvalidModelError.new model unless model.ancestors.include? ::ActiveRecord::Base raise DataTypeError.new text if text && !text.is_a?(String) @model = model @text = text evaluate end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
6 7 8 |
# File 'lib/nql/query.rb', line 6 def expression @expression end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/nql/query.rb', line 4 def model @model end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/nql/query.rb', line 5 def text @text end |
Instance Method Details
#ransack_search ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/nql/query.rb', line 16 def ransack_search if expression model.search(expression.to_ransack) else model.search end end |