Skip to content

Commit

Permalink
Add EmberCli::PathSet characterization tests
Browse files Browse the repository at this point in the history
`PathSet` involves the filesystem, but was previously implemented with
`Rails.root`.

This commit add configuration arguments to the `PathSet` constructor.

Adds test coverage using `tmp` directories.
  • Loading branch information
seanpdoyle committed Nov 6, 2015
1 parent 2658fd1 commit 2c25935
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 23 deletions.
2 changes: 2 additions & 0 deletions lib/ember-cli-rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "ember-cli/engine" if defined?(Rails)

module EmberCli
class DependencyError < StandardError; end

extend self

autoload :App, "ember-cli/app"
Expand Down
8 changes: 7 additions & 1 deletion lib/ember-cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ class BuildError < StandardError; end

def initialize(name, **options)
@name, @options = name.to_s, options
@paths = PathSet.new(self)
@paths = PathSet.new(
app: self,
configuration: EmberCli.configuration,
environment: Rails.env,
rails_root: Rails.root,
ember_cli_root: EmberCli.root,
)
end

def compile
Expand Down
53 changes: 31 additions & 22 deletions lib/ember-cli/path_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,42 @@ def self.define_path(name, &definition)
end
end

def initialize(app)
def initialize(app:, rails_root:, ember_cli_root:, environment:, configuration:)
@app = app
@configuration = configuration
@rails_root = rails_root
@environment = environment
@ember_cli_root = ember_cli_root
end

define_path :root do
path = app_options.fetch(:path){ default_root }
pathname = Pathname.new(path)
pathname.absolute?? pathname : Rails.root.join(path)
if pathname.absolute?
pathname
else
rails_root.join(path)
end
end

define_path :tmp do
root.join("tmp").tap(&:mkpath)
end

define_path :log do
Rails.root.join("log", "ember-#{app_name}.#{Rails.env}.log")
rails_root.join("log", "ember-#{app_name}.#{environment}.log")
end

define_path :dist do
EmberCli.root.join("apps", app_name).tap(&:mkpath)
ember_cli_root.join("apps", app_name).tap(&:mkpath)
end

define_path :assets do
EmberCli.root.join("assets").tap(&:mkpath)
ember_cli_root.join("assets").tap(&:mkpath)
end

define_path :applications do
Rails.root.join("public", "_apps").tap(&:mkpath)
rails_root.join("public", "_apps").tap(&:mkpath)
end

define_path :gemfile do
Expand All @@ -49,20 +57,26 @@ def initialize(app)
dist.join("tests")
end

define_path :node_modules do
root.join("node_modules")
end

define_path :package_json_file do
root.join("package.json")
end

define_path :node_modules do
root.join("node_modules")
define_path :addon_package_json_file do
node_modules.join("ember-cli-rails-addon", "package.json")
end

define_path :ember do
root.join("node_modules", ".bin", "ember").tap do |path|
fail <<-MSG.strip_heredoc unless path.executable?
No local ember executable found. You should run `npm install`
inside the #{app_name} app located at #{root}
MSG
unless path.executable?
fail DependencyError.new <<-MSG.strip_heredoc
No local ember executable found. You should run `npm install`
inside the #{app_name} app located at #{root}
MSG
end
end
end

Expand All @@ -75,34 +89,29 @@ def initialize(app)
end

define_path :tee do
app_options.fetch(:tee_path){ configuration.tee_path }
app_options.fetch(:tee_path) { configuration.tee_path }
end

define_path :bower do
app_options.fetch(:bower_path) { configuration.bower_path }
end

define_path :npm do
app_options.fetch(:npm_path){ configuration.npm_path }
app_options.fetch(:npm_path) { configuration.npm_path }
end

define_path :bundler do
app_options.fetch(:bundler_path){ configuration.bundler_path }
end

define_path :addon_package_json_file do
root.join("node_modules", "ember-cli-rails-addon", "package.json")
app_options.fetch(:bundler_path) { configuration.bundler_path }
end

private

attr_reader :app
attr_reader :app, :configuration, :ember_cli_root, :environment, :rails_root

delegate :name, :options, to: :app, prefix: true
delegate :configuration, to: EmberCli

def default_root
Rails.root.join(app_name)
rails_root.join(app_name)
end
end
end

0 comments on commit 2c25935

Please sign in to comment.