Class: RailsDb::SqlImport
- Inherits:
-
Object
- Object
- RailsDb::SqlImport
- Includes:
- Connection
- Defined in:
- lib/rails_db/sql_import.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(file) ⇒ SqlImport
constructor
A new instance of SqlImport.
- #valid? ⇒ Boolean
Methods included from Connection
#column_names, #column_properties, #columns, #connection, #to_param
Constructor Details
#initialize(file) ⇒ SqlImport
Returns a new instance of SqlImport.
7 8 9 |
# File 'lib/rails_db/sql_import.rb', line 7 def initialize(file) @file = file end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/rails_db/sql_import.rb', line 5 def result @result end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
5 6 7 |
# File 'lib/rails_db/sql_import.rb', line 5 def time @time end |
Instance Method Details
#import ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rails_db/sql_import.rb', line 17 def import valid? @time = Database.adapter.execute(@file.read) @result = Result.ok rescue RailsDbError, ActiveRecord::StatementInvalid => e @result = Result.new(e) end |
#valid? ⇒ Boolean
11 12 13 14 15 |
# File 'lib/rails_db/sql_import.rb', line 11 def valid? if @file.nil? raise RailsDbError.new('Please select valid SQL file and continue') end end |