Class: Zena::Use::QueryBuilder::ZafuMethods::DynamicQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/zena/use/query_builder.rb

Overview

Dynamic query mocks the QueryBuilder::Query

Instance Method Summary collapse

Constructor Details

#initialize(default, node, sql) ⇒ DynamicQuery

Returns a new instance of DynamicQuery.



154
155
156
# File 'lib/zena/use/query_builder.rb', line 154

def initialize(default, node, sql)
  @default, @node, @sql = default, node, sql
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

Pass all other methods to the default query.



169
170
171
# File 'lib/zena/use/query_builder.rb', line 169

def method_missing(meth, *args)
  @default.send(meth, *args)
end

Instance Method Details

#to_s(type = :find) ⇒ Object



158
159
160
161
162
163
164
165
166
# File 'lib/zena/use/query_builder.rb', line 158

def to_s(type = :find)
  base = "'#{@node.klass}', #{@node.to_s.inspect}, #{@sql}"
  case type
  when :find
    return "query(#{base})"
  else
    return "query(#{base}, :type => #{type.inspect})"
  end
end