Class: Ferry::Utilities
- Inherits:
-
Object
show all
- Defined in:
- lib/ferry/utilities.rb
Instance Method Summary
collapse
Instance Method Details
#check_valid_db(db) ⇒ Object
4
5
6
|
# File 'lib/ferry/utilities.rb', line 4
def check_valid_db(db)
%w[sqlite3 postgresql mysql2].include?(db) ? true : false
end
|
#check_valid_filetype(filepath) ⇒ Object
8
9
10
|
# File 'lib/ferry/utilities.rb', line 8
def check_valid_filetype(filepath)
%w[csv json sql yml].include?(filepath.split('.').last) ? true : false
end
|
#db_connect(environment) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/ferry/utilities.rb', line 12
def db_connect(environment)
db_config = YAML::load(IO.read("config/database.yml"))
if db_config[environment].nil?
raise "No database associated with #{environment} environment"
end
db_type = db_config[environment]["adapter"]
if ['sqlite3', 'postgresql', 'mysql2'].include?(db_type)
ActiveRecord::Base.establish_connection(adapter: db_type, database: db_config[environment]['database'])
puts "operating with "+db_type
return db_type
else
raise "#{db_type} is not supported by ferry at this time"
end
end
|
#execute(command) ⇒ Object
27
28
29
|
# File 'lib/ferry/utilities.rb', line 27
def execute(command)
`#{command}`
end
|
#print_version ⇒ Object
31
32
33
|
# File 'lib/ferry/utilities.rb', line 31
def print_version
puts "Ferry #{Ferry::VERSION}"
end
|