lib/skylight/cli.rb in skylight-3.1.5 vs lib/skylight/cli.rb in skylight-4.0.0.alpha

- old
+ new

@@ -1,16 +1,16 @@ -$:.unshift File.expand_path('../vendor/cli', __FILE__) +$LOAD_PATH.unshift File.expand_path("vendor/cli", __dir__) -require 'skylight' -require 'thor' -require 'yaml' -require 'highline' -require 'active_support/inflector' +require "skylight" +require "thor" +require "yaml" +require "highline" +require "active_support/inflector" -require 'skylight/cli/helpers' -require 'skylight/cli/doctor' -require 'skylight/cli/merger' +require "skylight/cli/helpers" +require "skylight/cli/doctor" +require "skylight/cli/merger" module Skylight module CLI # @api private class Base < Thor @@ -31,12 +31,12 @@ return end res = api.create_app(app_name, token) - config[:application] = res.get('app.id') - config[:authentication] = res.get('app.token') + config[:application] = res.get("app.id") + config[:authentication] = res.get("app.token") config.write(config_path) say "Congratulations. Your application is on Skylight! https://www.skylight.io", :green say <<-OUT @@ -77,66 +77,61 @@ user_config.save say "Environment warning disabled", :green end - private + private - def app_name - @app_name ||= - begin - name = nil + def app_name + @app_name ||= + begin + name = nil - if is_rails? - # Get the name in a process so that we don't pollute our environment here - # This is especially important since users may have things like WebMock that - # will prevent us from communicating with the Skylight API - begin - namefile = Tempfile.new('skylight-app-name') - # Windows appears to need double quotes for `rails runner` - `rails runner "File.open('#{namefile.path}', 'w') {|f| f.write(Rails.application.class.name) rescue '' }"` - name = namefile.read.split("::").first.underscore.titleize - name = nil if name.empty? - rescue => e - if ENV['DEBUG'] - puts e.class.name - puts e.to_s - puts e.backtrace.join("\n") + if rails? + # Get the name in a process so that we don't pollute our environment here + # This is especially important since users may have things like WebMock that + # will prevent us from communicating with the Skylight API + begin + namefile = Tempfile.new("skylight-app-name") + # Windows appears to need double quotes for `rails runner` + `rails runner "File.open('#{namefile.path}', 'w') {|f| f.write(Rails.application.class.name) rescue '' }"` + name = namefile.read.split("::").first.underscore.titleize + name = nil if name.empty? + rescue => e + if ENV["DEBUG"] + puts e.class.name + puts e.to_s + puts e.backtrace.join("\n") + end + ensure + namefile.close + namefile.unlink end - ensure - namefile.close - namefile.unlink - end - unless name - warn "Unable to determine Rails application name. Using directory name." + unless name + warn "Unable to determine Rails application name. Using directory name." + end end - end - unless name - name = File.basename(File.expand_path('.')).titleize + name || File.basename(File.expand_path(".")).titleize end + end - name - end - end + # Is this duplicated? + def relative_config_path + "config/skylight.yml" + end - # Is this duplicated? - def relative_config_path - 'config/skylight.yml' - end + def config_path + File.expand_path(relative_config_path) + end - def config_path - File.expand_path(relative_config_path) - end + def api + @api ||= Api.new(config) + end - def api - @api ||= Api.new(config) - end - - def user_config - config.user_config - end - + def user_config + config.user_config + end end end end