Class: DatabaseLoader::SqlFile

Inherits:
Object
  • Object
show all
Defined in:
lib/database_loader/sql_file.rb

Direct Known Subclasses

RubyFile

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/database_loader/sql_file.rb', line 3

def path
  @path
end

#usernameObject

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

#nameObject



13
14
15
# File 'lib/database_loader/sql_file.rb', line 13

def name
  File.basename(path)
end

#readObject



17
18
19
# File 'lib/database_loader/sql_file.rb', line 17

def read
  File.read(path)
end

#renderObject 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

#statementsObject



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

#typeObject



9
10
11
# File 'lib/database_loader/sql_file.rb', line 9

def type
  path.split(/[\/\\]/)[-2].to_sym
end