Class: Ferry::Utilities

Inherits:
Object
  • Object
show all
Defined in:
lib/ferry/utilities.rb

Direct Known Subclasses

Dumper, Exporter, Filler, Importer

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

#make_starter_fileObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ferry/utilities.rb', line 31

def make_starter_file
  if !File.exist?("lib/tasks/ferry.rake")
    install_dir = `bundle show ferry`.chomp
    starter_file_contents = File.open("#{install_dir}/doc/ferry_rake_contents.rb", "rb")
    contents = starter_file_contents.read
    File.open("lib/tasks/ferry.rake", 'w') {|f| f.write(contents)}
    puts "/lib/tasks/ferry.rake created!"
  else
    puts "/lib/tasks/ferry.rake already exists - but you knew that already ... didn't you?"
  end
end


43
44
45
# File 'lib/ferry/utilities.rb', line 43

def print_version
  puts "Ferry #{Ferry::VERSION}"
end