Class: Rigrate::DataSource
- Inherits:
-
Object
- Object
- Rigrate::DataSource
- Defined in:
- lib/rigrate/data_source.rb
Instance Attribute Summary collapse
-
#dbh ⇒ Object
Returns the value of attribute dbh.
Instance Method Summary collapse
-
#initialize(conn_uri) ⇒ DataSource
constructor
A new instance of DataSource.
- #method_missing(mth, *args, &block) ⇒ Object
- #sql(str, *args) ⇒ Object
Constructor Details
#initialize(conn_uri) ⇒ DataSource
Returns a new instance of DataSource.
9 10 11 12 |
# File 'lib/rigrate/data_source.rb', line 9 def initialize(conn_uri) uri = URI.parse(conn_uri) @dbh = eval(uri.scheme.capitalize).new conn_uri end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mth, *args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rigrate/data_source.rb', line 23 def method_missing(mth, *args, &block) begin table_name = mth columns = args str_sql = build_sql(table_name, *columns) @dbh.select(str_sql, &block) rescue Exception => e raise e end end |
Instance Attribute Details
#dbh ⇒ Object
Returns the value of attribute dbh.
7 8 9 |
# File 'lib/rigrate/data_source.rb', line 7 def dbh @dbh end |
Instance Method Details
#sql(str, *args) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/rigrate/data_source.rb', line 14 def sql(str, *args) begin @dbh.select(str, *args) rescue SQLite3::SQLException => e puts "DB: #{@dbh.inspect} SQL: #{str}" raise e end end |