Skip to content

Commit

Permalink
Introduce EmberCLI.env and ember_cli_rails_mode configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rwz committed Apr 1, 2015
1 parent a28b28c commit 4ff9ea1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
13 changes: 9 additions & 4 deletions lib/ember-cli-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand All @@ -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
7 changes: 3 additions & 4 deletions lib/ember-cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -202,7 +201,7 @@ def ember_app_name
end

def environment
non_production?? "development" : "production"
EmberCLI.env.production?? "production" : "development"
end

def package_json
Expand Down
22 changes: 13 additions & 9 deletions lib/ember-cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/ember-cli/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 4ff9ea1

Please sign in to comment.