class Dashing::CLI

Attributes

auth_token[RW]
name[R]

Public Class Methods

hyphenate(str) click to toggle source
# File lib/dashing/cli.rb, line 14
def hyphenate(str)
  return str.downcase if str =~ /^[A-Z-]+$/
  str.gsub('_', '-').gsub(/\B[A-Z]/, '-\&').squeeze('-').downcase
end

Public Instance Methods

__print_version() click to toggle source
# File lib/dashing/cli.rb, line 31
def __print_version
  say "#{Dashing::VERSION}"
end
generate(type, name) click to toggle source
# File lib/dashing/cli.rb, line 42
def generate(type, name)
  public_send("generate_#{type}".to_sym, name)
rescue NoMethodError => _e
  puts "Invalid generator. Either use widget, dashboard, or job"
end
install(gist_id, *args) click to toggle source
# File lib/dashing/cli.rb, line 49
def install(gist_id, *args)
  gist = Downloader.get_gist(gist_id)
  public_url = "https://gist.github.com/#{gist_id}"

  install_widget_from_gist(gist, args.include?('--skip'))

  print set_color("Don't forget to edit the ", :yellow)
  print set_color("Gemfile ", :yellow, :bold)
  print set_color("and run ", :yellow)
  print set_color("bundle install ", :yellow, :bold)
  say set_color("if needed. More information for this widget can be found at #{public_url}", :yellow)
rescue OpenURI::HTTPError => _http_error
  say set_color("Could not find gist at #{public_url}"), :red
end
job(name, auth_token = "") click to toggle source
# File lib/dashing/cli.rb, line 81
def job(name, auth_token = "")
  Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require_file(file) }
  self.class.auth_token = auth_token
  f = File.join(Dir.pwd, "jobs", "#{name}.rb")
  require_file(f)
end
new(name) click to toggle source
# File lib/dashing/cli.rb, line 36
def new(name)
  @name = Thor::Util.snake_case(name)
  directory(:project, @name)
end
start(*args) click to toggle source
# File lib/dashing/cli.rb, line 66
def start(*args)
  port_option = args.include?('-p') ? '' : ' -p 3030'
  args = args.join(' ')
  command = "bundle exec thin -R config.ru start#{port_option} #{args}"
  command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path]
  run_command(command)
end
stop() click to toggle source
# File lib/dashing/cli.rb, line 75
def stop
  command = "bundle exec thin stop"
  run_command(command)
end

Private Instance Methods

install_widget_from_gist(gist, skip_overwrite) click to toggle source
# File lib/dashing/cli.rb, line 103
def install_widget_from_gist(gist, skip_overwrite)
  gist['files'].each do |file, details|
    if file =~ /\.(html|coffee|scss)\z/
      widget_name = File.basename(file, '.*')
      new_path = File.join(Dir.pwd, 'widgets', widget_name, file)
      create_file(new_path, details['content'], :skip => skip_overwrite)
    elsif file.end_with?('.rb')
      new_path = File.join(Dir.pwd, 'jobs', file)
      create_file(new_path, details['content'], :skip => skip_overwrite)
    end
  end
end
require_file(file) click to toggle source
# File lib/dashing/cli.rb, line 116
def require_file(file)
  require file
end
run_command(command) click to toggle source
# File lib/dashing/cli.rb, line 95
def run_command(command)
  begin
    system(command)
  rescue Interrupt => _e
    say "Exiting..."
  end
end