module Reup::Helpers

Constants

DEFAULT_ENV_FILE
USER_ENV_FILE

Public Instance Methods

cocaine_run(command, quiet:) click to toggle source
# File lib/reup/helpers.rb, line 25
def cocaine_run(command, quiet:)
  cmd = Cocaine::CommandLine.new(command)
  result = cmd.run
  puts result unless quiet
  result
end
detect_change_to(files) { || ... } click to toggle source
# File lib/reup/helpers.rb, line 36
def detect_change_to(files, &block)
  before = files.map { |f| last_modified(f) }
  yield
  after  = files.map { |f| last_modified(f) }
  before != after # Not equal means there was a change
end
env() click to toggle source
# File lib/reup/helpers.rb, line 84
def env
  @env ||= (
    possible_envs = env_file.keys
    env = nil
    possible_envs.each do |possible|
      indicator_files = Array(env_file[possible]["indicator_files"])
      if indicator_files.any? { |f| File.exist? f }
        env = possible
        break
      end
    end
    raise "You don't appear to be in a supported environment" unless env
    env
  )
end
env_file() click to toggle source
# File lib/reup/helpers.rb, line 51
def env_file
  @env_file ||= (
    if File.exist? USER_ENV_FILE
      YAML.load_file USER_ENV_FILE
    else
      YAML.load_file DEFAULT_ENV_FILE
    end
  )
end
install(args = {}) click to toggle source

API methods

# File lib/reup/helpers.rb, line 104
def install(args = {})
  run install_command, args
end
install_command() click to toggle source
# File lib/reup/helpers.rb, line 65
def install_command
  @install_command ||= env_file[env]["install"]["command"]
end
kernel_run(command) click to toggle source
# File lib/reup/helpers.rb, line 32
def kernel_run(command)
  Kernel.exec command
end
last_modified(file) click to toggle source

Environment helpers

# File lib/reup/helpers.rb, line 47
def last_modified(file)
  File.mtime file
end
reset_db(args = {}) click to toggle source
# File lib/reup/helpers.rb, line 108
def reset_db(args = {})
  run reset_db_command, args
end
reset_db_command() click to toggle source
# File lib/reup/helpers.rb, line 73
def reset_db_command
  @reset_db_command ||= (
    db_section = env_file[env]["db"]
    if db_section
      db_section["reset_command"]
    else
      nil
    end
  )
end
run(command, quiet: false, print_command: true, replace_process: false) click to toggle source

Executable helpers

# File lib/reup/helpers.rb, line 13
def run(command, quiet: false, print_command: true, replace_process: false)
  return unless command
  puts command if print_command
  command += " &>/dev/null" if quiet

  if replace_process
    kernel_run command
  else
    cocaine_run command, quiet: quiet
  end
end
serve() click to toggle source
# File lib/reup/helpers.rb, line 112
def serve
  run(serve_command, replace_process: true)
end
serve_command() click to toggle source
# File lib/reup/helpers.rb, line 69
def serve_command
  @serve_command ||= env_file[env]["serve"]["command"]
end
watch_files() click to toggle source
# File lib/reup/helpers.rb, line 61
def watch_files
  @watch_files ||= Array(env_file[env]["install"]["only_if_changed"])
end