Class: NQL::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/nql/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#expressionObject (readonly)

Returns the value of attribute expression.



6
7
8
# File 'lib/nql/query.rb', line 6

def expression
  @expression
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/nql/query.rb', line 4

def model
  @model
end

#textObject (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_searchObject



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