class NativeQuery::Model
Represents instance of ORM model.
Constants
- RELEVANT_METHODS
Indicates relevant methods for binding to the connection object.
Public Class Methods
new(driver, configuration)
click to toggle source
Constructor.
# File lib/native-query/model.rb, line 46 def initialize(driver, configuration) @driver = driver @configuration = configuration end
Public Instance Methods
connection()
click to toggle source
Returns connection.
# File lib/native-query/model.rb, line 55 def connection if not @connection @connection = FluentQuery::Connection::new(@driver, @configuration) end @connection # returns end
method_missing(sym, *args, &block)
click to toggle source
Maps missing calls to tables.
Arguments are expected to be field names, so given to field query method.
# File lib/native-query/model.rb, line 70 def method_missing(sym, *args, &block) # If it's binding to the connection if sym.in? Model::RELEVANT_METHODS return self.connection.send(sym, *args, &block) # In otherwise, it's query request else query = Query::new(self.connection, sym) if args and not args.empty? query.fields(*args) end if not block.nil? result = query.instance_eval(&block) else result = query end return result end end