Class: SQLCapsule::Query

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

Defined Under Namespace

Classes: ArgumentCountMismatchError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sql, *args, &pre_processor) ⇒ Query

Returns a new instance of Query.



6
7
8
9
10
11
# File 'lib/sql_capsule/query.rb', line 6

def initialize(sql, *args, &pre_processor)
  @sql  = sql
  @args = args
  @pre_processor = pre_processor || Proc.new { |row| row }
  verify_arguments
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/sql_capsule/query.rb', line 3

def args
  @args
end

#pre_processorObject (readonly)

Returns the value of attribute pre_processor.



3
4
5
# File 'lib/sql_capsule/query.rb', line 3

def pre_processor
  @pre_processor
end

Instance Method Details

#add_post_processor(block) ⇒ Object



21
22
23
24
# File 'lib/sql_capsule/query.rb', line 21

def add_post_processor(block)
  block ||= Proc.new { |row| row }
  Proc.new { |row| block.call(pre_processor.call(row)) }
end

#filter_args(given_args) ⇒ Object



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

def filter_args(given_args)
  given_args.values_at(*args)
end

#to_sqlObject



13
14
15
# File 'lib/sql_capsule/query.rb', line 13

def to_sql
  sql.end_with?(";") ? sql : sql + ";"
end