Module: PgSync::Utils
Instance Method Summary collapse
- #colorize(message, color_code) ⇒ Object
- #config_file ⇒ Object
- #db_config_file(db) ⇒ Object
- #log(message = nil) ⇒ Object
- #search_tree(file) ⇒ Object
Instance Method Details
#colorize(message, color_code) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/pgsync/utils.rb', line 7 def colorize(, color_code) if $stderr.tty? "\e[#{color_code}m#{}\e[0m" else end end |
#config_file ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pgsync/utils.rb', line 15 def config_file return @config_file if instance_variable_defined?(:@config_file) @config_file = search_tree( if @options[:db] db_config_file(@options[:db]) else @options[:config] || ".pgsync.yml" end ) end |
#db_config_file(db) ⇒ Object
28 29 30 31 |
# File 'lib/pgsync/utils.rb', line 28 def db_config_file(db) return unless db ".pgsync-#{db}.yml" end |
#log(message = nil) ⇒ Object
3 4 5 |
# File 'lib/pgsync/utils.rb', line 3 def log( = nil) $stderr.puts end |
#search_tree(file) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pgsync/utils.rb', line 33 def search_tree(file) path = Dir.pwd # prevent infinite loop 20.times do absolute_file = File.join(path, file) if File.exist?(absolute_file) break absolute_file end path = File.dirname(path) break if path == "/" end end |