From 780fe49f715c2fced88e958b02541bf8e7dca934 Mon Sep 17 00:00:00 2001 From: Daniel Beauchamp Date: Wed, 8 Aug 2012 18:02:56 -0400 Subject: Rename project to 'Dashing', and do some other cleanups --- bin/dashing | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/things | 81 ------------------------------------------------------------ 2 files changed, 82 insertions(+), 81 deletions(-) create mode 100755 bin/dashing delete mode 100755 bin/things (limited to 'bin') diff --git a/bin/dashing b/bin/dashing new file mode 100755 index 0000000..32c89c8 --- /dev/null +++ b/bin/dashing @@ -0,0 +1,82 @@ +#!/usr/bin/env ruby + +require 'thor' +require 'net/http' +require 'json' + +class MockScheduler + def method_missing(*args) + yield + end +end + +def send_event(id, data) + req = Net::HTTP::Post.new("/widgets/#{id}") + req["content-type"] = "application/json" + req.body = JSON.unparse(data.merge(:auth_token => Dashing::CLI.auth_token)) + res = Net::HTTP.new('localhost', 3000).start { |http| http.request(req) } + puts "Data Sent to #{id}: #{data}" +end + +SCHEDULER = MockScheduler.new + +module Dashing + + class CLI < Thor + include Thor::Actions + + class << self + attr_accessor :auth_token + end + + attr_accessor :name + + no_tasks do + ['widget', 'dashboard', 'job'].each do |type| + define_method "generate_#{type}" do |name| + @name = Thor::Util.snake_case(name) + directory type.to_sym, File.join("#{type}s") + end + end + end + + def self.source_root + File.expand_path('../../templates', __FILE__) + end + + desc "new PROJECT_NAME", "Sets up ALL THE THINGS needed for your dashboard project structure." + def new(name) + @name = Thor::Util.snake_case(name) + directory :project, @name + end + + desc "generate GENERATOR NAME", "Creates a new widget with all the fixins'" + def generate(type, name) + send("generate_#{type}".to_sym, name) + rescue NoMethodError => e + puts "Invalid generator. Either use widget, dashboard, or job" + end + map "g" => :generate + + desc "start", "Starts the server in style!" + method_option :job_path, :desc => "Specify the directory where jobs are stored" + def start(*args) + args = args.join(" ") + command = "bundle exec thin -R config.ru start #{args}" + command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path] + system(command) + end + map "s" => :start + + desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job." + def job(name, auth_token = "") + Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file } + self.class.auth_token = auth_token + f = File.join(Dir.pwd, "jobs", "#{name}.rb") + require f + end + + end +end + +Dashing::CLI.start \ No newline at end of file diff --git a/bin/things b/bin/things deleted file mode 100755 index 0ad9eb3..0000000 --- a/bin/things +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env ruby - -require 'thor' -require 'net/http' -require 'json' - -class MockScheduler - def method_missing(*args) - yield - end -end - -def send_event(id, data) - req = Net::HTTP::Post.new("/widgets/#{id}") - req["content-type"] = "application/json" - req.body = JSON.unparse(data.merge(:auth_token => AllTheThings::CLI.auth_token)) - res = Net::HTTP.new('localhost', 3000).start { |http| http.request(req) } - puts "Data Sent to #{id}: #{data}" -end - -SCHEDULER = MockScheduler.new - -module AllTheThings - - class CLI < Thor - include Thor::Actions - - class << self - attr_accessor :auth_token - end - - attr_accessor :name - - no_tasks do - ['widget', 'dashboard', 'job'].each do |type| - define_method "generate_#{type}" do |name| - @name = Thor::Util.snake_case(name) - directory type.to_sym, File.join("#{type}s") - end - end - end - - def self.source_root - File.expand_path('../../templates', __FILE__) - end - - desc "new PROJECT_NAME", "Sets up ALL THE THINGS needed for your dashboard project structure." - def new(name) - @name = Thor::Util.snake_case(name) - directory :project, @name - end - - desc "generate GENERATOR NAME", "Creates a new widget with all the fixins'" - def generate(type, name) - send("generate_#{type}".to_sym, name) - rescue NoMethodError => e - puts "Invalid generator. Either use widget, dashboard, or job" - end - map "g" => :generate - - desc "start", "Starts the server in style!" - method_option :job_path, :desc => "Specify the directory where jobs are stored" - def start(*args) - args = args.join(" ") - command = "bundle exec thin -R config.ru start #{args}" - command.prepend "export JOB_PATH=#{options[:job_path]}; " if options[:job_path] - system(command) - end - - desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job." - def job(name, auth_token = "") - Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file } - self.class.auth_token = auth_token - f = File.join(Dir.pwd, "jobs", "#{name}.rb") - require f - end - - end -end - -AllTheThings::CLI.start \ No newline at end of file -- cgit v1.2.3