Class: Dashing::CLI
- Inherits:
-
Thor
- Object
- Thor
- Dashing::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/dashing/cli.rb
Class Attribute Summary collapse
-
.auth_token ⇒ Object
Returns the value of attribute auth_token.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #generate(type, name) ⇒ Object
- #install(gist_id, *args) ⇒ Object
- #job(name, auth_token = "") ⇒ Object
- #new(name) ⇒ Object
- #start(*args) ⇒ Object
- #stop ⇒ Object
Class Attribute Details
.auth_token ⇒ Object
Returns the value of attribute auth_token.
11 12 13 |
# File 'lib/dashing/cli.rb', line 11 def auth_token @auth_token end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/dashing/cli.rb', line 8 def name @name end |
Class Method Details
.hyphenate(str) ⇒ Object
13 14 15 16 |
# 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 |
Instance Method Details
#generate(type, name) ⇒ Object
35 36 37 38 39 |
# 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, *args) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dashing/cli.rb', line 42 def install(gist_id, *args) gist = Downloader.get_gist(gist_id) public_url = "https://gist.github.com/#{gist_id}" (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 = "") ⇒ Object
74 75 76 77 78 79 |
# 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) ⇒ Object
29 30 31 32 |
# File 'lib/dashing/cli.rb', line 29 def new(name) @name = Thor::Util.snake_case(name) directory(:project, @name) end |
#start(*args) ⇒ Object
59 60 61 62 63 64 65 |
# 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=#{[:job_path]}; " if [:job_path] run_command(command) end |
#stop ⇒ Object
68 69 70 71 |
# File 'lib/dashing/cli.rb', line 68 def stop command = "bundle exec thin stop" run_command(command) end |