require 'git' require 'yaml' require 'httparty' require 'json' module Railsonfire module Helper def shell Thor::Base.shell.new end def notify class_name, message, parameters = {} token = Railsonfire.user ? Railsonfire.user.railsonfire_token : "" post_json "#{Railsonfire::DOMAIN}/airbrake/proxy", { "error_class" => class_name, "error_message" => message + " - #{token}", "parameters" => parameters.merge({:railsonfire_id => token}) } end def send_signal signal begin token = Railsonfire.user ? Railsonfire.user.railsonfire_token : "" HTTParty.post("#{Railsonfire::DOMAIN}/users/signal?railsonfire_token=#{token}&signal=#{signal}") rescue Exception => e notify e.class, e.message end end def is_git_managed? dir_exists?("./.git").tap do |git_folder| error "Start railsonfire in the root folder of a git managed project" unless git_folder end end def write_config_file create_file( Railsonfire::RAILSONFIRE_FILE, Railsonfire.config.to_yaml.gsub("---\n", "").gsub("\n\n", "\n").gsub(": \n", ":\n"), :force => true ) end def success message say message, Thor::Shell::Color::GREEN end def error message say message, Thor::Shell::Color::RED end def warning message say message, Thor::Shell::Color::YELLOW end def heroku @heroku ||= ::Heroku::Auth.api end def select msg, elements elements.each_with_index do |element, index| success(block_given? ? yield(element, index + 1) : ("%s. %s" % [index + 1, element])) end result = ask(msg, :limited_to => (1..elements.count).map(&:to_s)).to_i elements[result - 1] end def post_json path, body HTTParty.post(path, :headers => {"Content-Type" => "application/json"}, :body => body.to_json) end private def dir_exists? dir File.exists?(dir) && File.directory?(dir) end end end