diff --git a/lib/ember-cli-rails.rb b/lib/ember-cli-rails.rb index d365758e..f8491c14 100644 --- a/lib/ember-cli-rails.rb +++ b/lib/ember-cli-rails.rb @@ -39,10 +39,7 @@ def prepare! def enable! prepare! - - if Helpers.use_middleware? - Rails.configuration.middleware.use Middleware - end + append_middleware unless env.production? end def install_dependencies! @@ -77,6 +74,10 @@ def root @root ||= Rails.root.join("tmp", "ember-cli-#{uid}") end + def env + @env ||= Helpers.current_environment.inquiry + end + delegate :apps, to: :configuration private @@ -92,4 +93,8 @@ def cleanup def each_app apps.each{ |name, app| yield app } end + + def append_middleware + Rails.configuration.middleware.use Middleware + end end diff --git a/lib/ember-cli/app.rb b/lib/ember-cli/app.rb index a09e6a0b..b339ea9a 100644 --- a/lib/ember-cli/app.rb +++ b/lib/ember-cli/app.rb @@ -100,14 +100,13 @@ def respond_to_missing?(method_name, *) private - delegate :match_version?, :non_production?, to: Helpers def supported_path_method(original) path_method = original.to_s[/\A(.+)_path\z/, 1] path_method if path_method && paths.respond_to?(path_method) end def silence_build(&block) - if ENV.fetch("EMBER_CLI_RAILS_VERBOSE"){ !non_production? } + if ENV.fetch("EMBER_CLI_RAILS_VERBOSE"){ EmberCLI.env.production? } yield else silence_stream STDOUT, &block @@ -151,7 +150,7 @@ def prepare def check_ember_cli_version! version = dev_dependencies.fetch("ember-cli").split(?-).first - unless match_version?(version, EMBER_CLI_VERSION) + unless Helpers.match_version?(version, EMBER_CLI_VERSION) fail <<-MSG.strip_heredoc EmberCLI Rails require ember-cli NPM package version to be #{EMBER_CLI_VERSION} to work properly. From within your EmberCLI directory @@ -202,7 +201,7 @@ def ember_app_name end def environment - non_production?? "development" : "production" + EmberCLI.env.production?? "production" : "development" end def package_json diff --git a/lib/ember-cli/helpers.rb b/lib/ember-cli/helpers.rb index 933d9534..efddc4c2 100644 --- a/lib/ember-cli/helpers.rb +++ b/lib/ember-cli/helpers.rb @@ -24,21 +24,25 @@ def which(cmd) nil end - def non_production? - !Rails.env.production? && rails_config_for(:consider_all_requests_local) + def current_environment + rails_config_for(:ember_cli_rails_mode){ default_environment }.to_s end - def use_middleware? - rails_config_for(:use_ember_middleware, non_production?) - end + private - def use_live_recompilation? - rails_config_for(:use_ember_live_recompilation, Rails.env.development?) + def default_environment + if Rails.env.test? + "test" + elsif Rails.env.production? || !rails_config_for(:consider_all_requests_local) + "production" + else + "development" + end end - def rails_config_for(key, default=false) + def rails_config_for(key) config = Rails.configuration - config.respond_to?(key) ? config.public_send(key) : default + config.respond_to?(key) ? config.public_send(key) : yield end end end diff --git a/lib/ember-cli/middleware.rb b/lib/ember-cli/middleware.rb index 51c581ce..44b33661 100644 --- a/lib/ember-cli/middleware.rb +++ b/lib/ember-cli/middleware.rb @@ -19,7 +19,7 @@ def call(env) def enable_ember_cli @enabled ||= begin - if Helpers.use_live_recompilation? + if EmberCLI.env.development? EmberCLI.run! else EmberCLI.compile!