Class: Warrant::WarrantQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/warrant/warrant_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWarrantQuery

Returns a new instance of WarrantQuery.



7
8
9
10
11
# File 'lib/warrant/warrant_query.rb', line 7

def initialize
    @select_clause = []
    @for_clause = {}
    @where_clause = {}
end

Instance Attribute Details

#for_clauseObject

Returns the value of attribute for_clause.



5
6
7
# File 'lib/warrant/warrant_query.rb', line 5

def for_clause
  @for_clause
end

#select_clauseObject

Returns the value of attribute select_clause.



5
6
7
# File 'lib/warrant/warrant_query.rb', line 5

def select_clause
  @select_clause
end

#where_clauseObject

Returns the value of attribute where_clause.



5
6
7
# File 'lib/warrant/warrant_query.rb', line 5

def where_clause
  @where_clause
end

Instance Method Details

#for(for_filters) ⇒ Object



23
24
25
26
# File 'lib/warrant/warrant_query.rb', line 23

def for(for_filters)
    @for_clause = @for_clause.merge(for_filters)
    self
end

#select(*object_types) ⇒ Object



13
14
15
16
# File 'lib/warrant/warrant_query.rb', line 13

def select(*object_types)
    @select_clause = object_types
    self
end

#select_explicit(*object_types) ⇒ Object



18
19
20
21
# File 'lib/warrant/warrant_query.rb', line 18

def select_explicit(*object_types)
    @select_clause = "explicit #{object_types}"
    self
end

#to_query_paramObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/warrant/warrant_query.rb', line 33

def to_query_param
    if @select_clause.length == 0 || @for_clause.empty?
        raise "Must have a select and for clause"
    end

    query = "SELECT #{@select_clause.join(",")} FOR #{filters_hash_to_string(@for_clause)}"
    query += " WHERE #{filters_hash_to_string(@where_clause)}" unless @where_clause.empty?

    query
end

#where(where_filters) ⇒ Object



28
29
30
31
# File 'lib/warrant/warrant_query.rb', line 28

def where(where_filters)
    @where_clause = @where_clause.merge(where_filters)
    self
end