Module: RailsSetup::Environment

Defined in:
lib/rails_setup/environment.rb

Instance Method Summary collapse

Instance Method Details

#checkmarkObject



12
13
14
# File 'lib/rails_setup/environment.rb', line 12

def checkmark
  "\u2713 ".color(:green)
end

#consoleObject



8
9
10
# File 'lib/rails_setup/environment.rb', line 8

def console
  @console ||= HighLine.new
end

#create_file(file, name, requires_edit = false) ⇒ Object

Creates a file based on a ‘.example’ version saved in the same folder Will optionally open the new file in the default editor after creation



55
56
57
58
59
60
61
62
63
# File 'lib/rails_setup/environment.rb', line 55

def create_file(file, name, requires_edit=false)
  FileUtils.cp(file + '.example', file)

  if requires_edit
    puts "Update #{file} and run `bundle exec rake setup` to continue".color(:red)
    system(ENV['EDITOR'], file) unless ENV['EDITOR'].blank?
    exit
  end
end

#done(message) ⇒ Object



20
21
22
# File 'lib/rails_setup/environment.rb', line 20

def done(message)
  puts "#{checkmark} #{message}"
end

#find_or_create_file(file, name, requires_edit = false) ⇒ Object

Looks for the specificed file and creates it if it does not exist



67
68
69
70
71
72
73
# File 'lib/rails_setup/environment.rb', line 67

def find_or_create_file(file, name, requires_edit=false)
  if File.exists?(file)
    file
  else
    create_file(file, name, requires_edit)
  end
end

#heartObject



16
17
18
# File 'lib/rails_setup/environment.rb', line 16

def heart
  "\u2665 ".color(:red)
end

#section(description) ⇒ Object



24
25
26
27
28
29
# File 'lib/rails_setup/environment.rb', line 24

def section(description)
  puts # Empty Line
  puts description.underline
  puts # Empty Line
  yield
end

#silenceObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_setup/environment.rb', line 31

def silence
  begin
    orig_stderr = $stderr.clone
    orig_stdout = $stdout.clone

    $stderr.reopen File.new('/dev/null', 'w')
    $stdout.reopen File.new('/dev/null', 'w')

    return_value = yield
  rescue Exception => e
    $stdout.reopen orig_stdout
    $stderr.reopen orig_stderr
    raise e
  ensure
    $stdout.reopen orig_stdout
    $stderr.reopen orig_stderr
  end

  return_value
end