class Flatrack::CLI

The command line interface for flatrack

Constants

BIN_COPY_FILES

@private

FILES

@private

KEEP_DIRS

@private

SRC_ROOT

@private

Public Instance Methods

__default__() click to toggle source

Info about flatrack

# File lib/flatrack/cli.rb, line 85
def __default__
  if options[:version]
    puts 'Flatrack ' + Flatrack::VERSION
    return
  end
end
new(path) click to toggle source

Create a new app @param path [String]

# File lib/flatrack/cli.rb, line 49
def new(path)
  mkdir_p path
  full_path             = File.expand_path path
  @name                 = File.basename(full_path).titleize
  self.destination_root = full_path
  write_keeps
  write_files
  bundle!
end
start() click to toggle source

Start the app

# File lib/flatrack/cli.rb, line 65
def start
  Flatrack.config do |config|
    config.site_root   = options[:root]
  end
  begin
    require File.join Dir.pwd, 'boot'
  rescue LoadError
    nil
  end
  run_opts             = {}
  run_opts[:app]       = Flatrack::Site
  run_opts[:Port]      = options[:port]
  run_opts[:Logger]    = Logger.new('/dev/null') unless options[:verbose]
  run_opts[:AccessLog] = Logger.new('/dev/null') unless options[:verbose]
  Rack::Server.start run_opts
end

Private Instance Methods

bundle!() click to toggle source
# File lib/flatrack/cli.rb, line 96
def bundle!
  Dir.chdir(destination_root) do
    cmd = 'bundle install'
    cmd << ' --quiet' unless options[:verbose]
    system cmd
  end if options[:bundle]
end
write_files() click to toggle source
# File lib/flatrack/cli.rb, line 110
def write_files
  FILES.each do |temp, dest|
    template temp, dest, verbose: options[:verbose]
  end
  BIN_COPY_FILES.each do |src, dest|
    src = File.join SRC_ROOT, src
    copy_file src, dest, verbose: options[:verbose]
  end
end
write_keeps() click to toggle source
# File lib/flatrack/cli.rb, line 104
def write_keeps
  KEEP_DIRS.each do |dir|
    template '.keep', File.join(dir, '.keep'), verbose: options[:verbose]
  end
end