Class: DatabaseLoader::SqlFile
- Inherits:
-
Object
- Object
- DatabaseLoader::SqlFile
- Defined in:
- lib/database_loader/sql_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(path) ⇒ SqlFile
constructor
A new instance of SqlFile.
- #name ⇒ Object
- #read ⇒ Object
- #render ⇒ Object (also: #to_s)
- #statements ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(path) ⇒ SqlFile
Returns a new instance of SqlFile.
5 6 7 |
# File 'lib/database_loader/sql_file.rb', line 5 def initialize(path) self.path = path end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/database_loader/sql_file.rb', line 3 def path @path end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/database_loader/sql_file.rb', line 3 def username @username end |
Instance Method Details
#name ⇒ Object
13 14 15 |
# File 'lib/database_loader/sql_file.rb', line 13 def name File.basename(path) end |
#read ⇒ Object
17 18 19 |
# File 'lib/database_loader/sql_file.rb', line 17 def read File.read(path) end |
#render ⇒ Object Also known as: to_s
21 22 23 |
# File 'lib/database_loader/sql_file.rb', line 21 def render Template.new(read).render("username" => username) end |
#statements ⇒ Object
26 27 28 29 30 |
# File 'lib/database_loader/sql_file.rb', line 26 def statements render.split(/\r?\n\/\r?\n/).reject(&:blank?).map do |str| SqlStatement.new(str) end end |
#type ⇒ Object
9 10 11 |
# File 'lib/database_loader/sql_file.rb', line 9 def type path.split(/[\/\\]/)[-2].to_sym end |