Module: Rake::CommonTasks::Helpers

Defined in:
lib/rake/common_tasks.rb

Instance Method Summary collapse

Instance Method Details

#check_env!Object



30
31
32
# File 'lib/rake/common_tasks.rb', line 30

def check_env!
  raise "RACK_ENV unknown" if ENV['RACK_ENV'].nil? || ENV['RACK_ENV'] == ''
end

#is_local?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/rake/common_tasks.rb', line 34

def is_local?
  check_env!
  %w(development test).include? ENV['RACK_ENV']
end

#is_production?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/rake/common_tasks.rb', line 39

def is_production?
  check_env!
  ENV['RACK_ENV'] == 'production'
end

#progress_bar(total = 0) ⇒ Object



44
45
46
# File 'lib/rake/common_tasks.rb', line 44

def progress_bar(total = 0)
  ::ProgressBar.new(total, :bar, :counter, :rate)
end

#system_try_and_fail(command) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/rake/common_tasks.rb', line 21

def system_try_and_fail(command)
  sh command do |ok, res|
    if !ok
      yield if block_given?
      raise "COMMAND FAILED: Error running #{command} (Pwd: #{Dir.pwd}, exit status:#{res.exitstatus}). Aborting"
    end
  end
end

#test_db_nameObject



48
49
50
51
52
53
54
# File 'lib/rake/common_tasks.rb', line 48

def test_db_name
  if ENV['DATABASE_NAME'].nil? or ENV['DATABASE_NAME'] == ''
    raise "ENV['DATABASE_NAME'] is nil or blank!"
  end

  "#{ENV['DATABASE_NAME']}_test"
end