Top Level Namespace

Defined Under Namespace

Modules: Omeka

Instance Method Summary collapse

Instance Method Details

#ask(message, default = true) ⇒ Object

Prompt user for a message



45
46
47
# File 'lib/helpers.rb', line 45

def ask(message, default=true)
  Capistrano::CLI.ui.agree(message)
end

#docs_pathObject



29
30
31
# File 'lib/helpers.rb', line 29

def docs_path
  expand_path_for('../doc')
end

#environmentObject

Automatically ests the environment based on presence of :stage (multistage gem), :rails_env, or RAILS_ENV variable; otherwise defaults to ‘production’



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/helpers.rb', line 8

def environment
  if exists?(:stage)
    stage
  elsif exists(:rails_env)
    rails_env
  elsif(ENV['RAILS_ENV'])
    ENV['RAILS_ENV']
  else
    "production"
  end
end

#expand_path_for(path) ⇒ Object



33
34
35
36
# File 'lib/helpers.rb', line 33

def expand_path_for(path)
  expanded = File.join(File.dirname(__FILE__), path)
  File.expand_path(expanded)
end

#generate_config(local_file, remote_file) ⇒ Object

Generate a configuration file for parsing through ERB Fetches file and uploads it to remote_file Make suer you user has the correct permissions



52
53
54
55
56
57
58
# File 'lib/helpers.rb', line 52

def generate_config(local_file, remote_file)
  temp_file = '/tmp' + File.basename(local_file)
  buffer = parse_config(local_file)
  File.open(temp_file, 'w+') { |f| f << buffer }
  upload temp_file, remote_file, :via => :scp
  `rm #{temp_file}`
end

#is_using(something, with_some_var) ⇒ Object



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

def is_using(something, with_some_var)
  exists?(with_some_var.to_sym) && fetch(with_some_var.to_sym).to_s.downcase == something
end

#parse_config(file) ⇒ Object



38
39
40
41
42
# File 'lib/helpers.rb', line 38

def parse_config(file)
  require 'erb' # render not available in Capistrano 2
  template = File.read(file) 
  return ERB.new(template).result(binding)
end

#run_rake(task) ⇒ Object

Executes a basic rake task



61
62
63
# File 'lib/helpers.rb', line 61

def run_rake(task)
  run "cd #{current_path} && rake #{task} RAILS_ENV=#{environment}"
end

#templates_pathObject

Path where generators live



25
26
27
# File 'lib/helpers.rb', line 25

def templates_path
  expand_path_for('../generators')
end