Class: FluentQuery::Query

Inherits:
FluentQuery::Queries::Abstract show all
Defined in:
lib/fluent-query/query.rb

Overview

Represents single query.

Instance Attribute Summary collapse

Attributes inherited from FluentQuery::Queries::Abstract

#connection

Instance Method Summary collapse

Methods inherited from FluentQuery::Queries::Abstract

#all, #assoc, #do, #each, #execute, #find_all, #map, #one, #processor, #single

Constructor Details

#initialize(connection) ⇒ Query

Returns a new instance of Query.



28
29
30
31
# File 'lib/fluent-query/query.rb', line 28

def initialize(connection)
    super(connection)
    @stack = [ ]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fluent-query/query.rb', line 38

def method_missing(sym, *args, &block)
    driver = @connection.driver
    _sym, args = driver.correct_token(sym, args)
# p [sym, args]
    self.push_token(_sym, args)
    conditionally = driver.check_conditionally(self, sym, *args, &block)
    
    if not conditionally.nil?
        result = conditionally
    else
        result = self
    end
   
    return result
end

Instance Attribute Details

#stackObject (readonly)

Returns the value of attribute stack.



21
22
23
# File 'lib/fluent-query/query.rb', line 21

def stack
  @stack
end

Instance Method Details

#buildObject Also known as: build!



88
89
90
# File 'lib/fluent-query/query.rb', line 88

def build
    @connection.driver.build_query(self)
end

#compileObject Also known as: compile!



100
101
102
# File 'lib/fluent-query/query.rb', line 100

def compile
    FluentQuery::Queries::Compiled::new(@connection, self)
end

#prepareObject Also known as: prepare!



112
113
114
# File 'lib/fluent-query/query.rb', line 112

def prepare
    FluentQuery::Queries::Prepared::new(@connection, self)
end

#push_token(name, arguments) ⇒ Object



59
60
61
# File 'lib/fluent-query/query.rb', line 59

def push_token(name, arguments)
    @stack << FluentQuery::Token::new(name, arguments)
end

#query(*args) ⇒ Object



68
69
70
71
# File 'lib/fluent-query/query.rb', line 68

def query(*args)
    @stack << FluentQuery::Tokens::Raw::new(args)
    return self
end

#typeObject



79
80
81
# File 'lib/fluent-query/query.rb', line 79

def type
    self.stack.first.name.to_sym
end