Class: Perpetuity::Postgres::Query

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Query

Returns a new instance of Query.



9
10
11
12
13
14
15
# File 'lib/perpetuity/postgres/query.rb', line 9

def initialize &block
  if block_given?
    @query = block
  else
    @query = proc { NilQuery.new }
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



29
30
31
# File 'lib/perpetuity/postgres/query.rb', line 29

def method_missing name
  QueryAttribute.new(name)
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



7
8
9
# File 'lib/perpetuity/postgres/query.rb', line 7

def klass
  @klass
end

#queryObject (readonly)

Returns the value of attribute query.



7
8
9
# File 'lib/perpetuity/postgres/query.rb', line 7

def query
  @query
end

Instance Method Details

#to_dbObject



17
18
19
# File 'lib/perpetuity/postgres/query.rb', line 17

def to_db
  query.call(self).to_db
end

#to_sObject



25
26
27
# File 'lib/perpetuity/postgres/query.rb', line 25

def to_s
  to_db
end

#to_strObject



21
22
23
# File 'lib/perpetuity/postgres/query.rb', line 21

def to_str
  to_db
end