class Railyard::CLI

Public Instance Methods

expand_path(path) click to toggle source
# File lib/railyard.rb, line 103
def expand_path(path)
  path[0] == "/" ? path : working_directory.join(path)
end
gemfile_path() click to toggle source
# File lib/railyard.rb, line 99
def gemfile_path
  sandbox_path.join("Gemfile")
end
help() click to toggle source
Calls superclass method
# File lib/railyard.rb, line 66
def help
  puts "railyard #{Railyard::VERSION}"
  super
end
install() click to toggle source
# File lib/railyard.rb, line 85
def install
  sandbox("bundle install --path vendor > /dev/null")
end
installed?() click to toggle source
# File lib/railyard.rb, line 81
def installed?
  sandbox("bundle check > /dev/null")
end
new(app_path = nil, *args) click to toggle source
# File lib/railyard.rb, line 33
def new(app_path = nil, *args)
  if !installed?
    puts "Installing Rails..."
    install
  end

  if app_path && app_path !~ /^--?/
    args.unshift expand_path(app_path)
    args << "--skip-bundle" unless args.include?("--skip-bundle")
  else
    args << "--help"
  end

  rails_new(args)
end
plugin(app_path = nil, *args) click to toggle source
# File lib/railyard.rb, line 50
def plugin(app_path = nil, *args)
  if !installed?
    puts "Installing Rails..."
    install
  end

  if app_path && app_path !~ /^--?/
    args.unshift expand_path(app_path)
    args << "--skip-bundle" unless args.include?("--skip-bundle")
  else
    args << "--help"
  end

  rails_plugin(args)
end
rails_new(args) click to toggle source
# File lib/railyard.rb, line 73
def rails_new(args)
  sandbox("bundle exec rails new #{args.join(' ')}")
end
rails_plugin(args) click to toggle source
# File lib/railyard.rb, line 77
def rails_plugin(args)
  sandbox("bundle exec rails plugin new #{args.join(' ')}")
end
sandbox(command) click to toggle source
# File lib/railyard.rb, line 89
def sandbox(command)
  Bundler.with_clean_env do
    system("cd #{sandbox_path}; #{command}")
  end
end
sandbox_path() click to toggle source
# File lib/railyard.rb, line 95
def sandbox_path
  Pathname.new(File.expand_path("../../sandbox", __FILE__))
end
version(number = nil) click to toggle source
# File lib/railyard.rb, line 13
def version(number = nil)
  if number
    message = installed? ? "Changing Rails version..." : "Installing Rails..."

    Gemfile.new(gemfile_path).update_version(number)
    puts message

    success = install
    puts "Rails version #{number} doesn't appear to exist." unless success
  else
    if !installed?
      puts "Installing Rails..."
      install
    end

    sandbox("bundle exec rails --version")
  end
end
working_directory() click to toggle source
# File lib/railyard.rb, line 107
def working_directory
  Pathname.new(Dir.pwd)
end