class Dashing::CLI
Attributes
auth_token[RW]
name[R]
Public Class Methods
hyphenate(str)
click to toggle source
# File lib/dashing/cli.rb, line 13 def hyphenate(str) return str.downcase if str =~ /^[A-Z-]+$/ str.gsub('_', '-').gsub(/\B[A-Z]/, '-\&').squeeze('-').downcase end
Public Instance Methods
generate(type, name)
click to toggle source
# File lib/dashing/cli.rb, line 35 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)
click to toggle source
# File lib/dashing/cli.rb, line 42 def install(gist_id) gist = Downloader.get_gist(gist_id) public_url = "https://gist.github.com/#{gist_id}" install_widget_from_gist(gist) 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 74 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 29 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 59 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 68 def stop command = "bundle exec thin stop" run_command(command) end
Private Instance Methods
install_widget_from_gist(gist)
click to toggle source
# File lib/dashing/cli.rb, line 92 def install_widget_from_gist(gist) 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']) elsif file.end_with?('.rb') new_path = File.join(Dir.pwd, 'jobs', file) create_file(new_path, details['content']) end end end
require_file(file)
click to toggle source
# File lib/dashing/cli.rb, line 105 def require_file(file) require file end
run_command(command)
click to toggle source
# File lib/dashing/cli.rb, line 88 def run_command(command) system(command) end