Class: SQLCapsule::Query
- Inherits:
-
Object
- Object
- SQLCapsule::Query
- Defined in:
- lib/sql_capsule/query.rb
Defined Under Namespace
Classes: ArgumentCountMismatchError
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#pre_processor ⇒ Object
readonly
Returns the value of attribute pre_processor.
Instance Method Summary collapse
- #add_post_processor(block) ⇒ Object
- #filter_args(given_args) ⇒ Object
-
#initialize(sql, *args, &pre_processor) ⇒ Query
constructor
A new instance of Query.
- #to_sql ⇒ Object
Constructor Details
#initialize(sql, *args, &pre_processor) ⇒ 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
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/sql_capsule/query.rb', line 3 def args @args end |
#pre_processor ⇒ Object (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.select { |key, value| args.include?(key) }.values end |
#to_sql ⇒ Object
13 14 15 |
# File 'lib/sql_capsule/query.rb', line 13 def to_sql sql.end_with?(";") ? sql : sql + ";" end |