Skip to content

Commit f510fe8

Browse files
committed
Introduce App#mountable? and App#to_rack
For deploys that need to be mounted to be useful, [`File`][file] for example, this commit exposes an API for encapsulating that logic. `App#to_rack` will create an instance of a `Rack` application that can be mounted via `mount $RACK_APP => "/path"`. For deploys that don't serve assets from the file system, [`Redis`][redis] for example, `mountable?` should return `false`. [file]: https://github.com/thoughtbot/ember-cli-rails/blob/v0.7.0/lib/ember_cli/deploy/file.rb [redis]: https://github.com/seanpdoyle/ember-cli-rails-deploy-redis
1 parent 9d0c3fb commit f510fe8

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
master
22
------
33

4+
* Introduce the idea of `App#mountable?` and `App#to_rack` for handling deploys
5+
that don't serve assets from the file system (Redis, for example).
46
* Fix bug with generated `bin/heroku_install` script iterating through multiple
57
* Don't mount route helpers at top-level. Instead, mount within the surrounding
68
context with which they're invoked. [#381]

lib/ember_cli/app.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ def check_for_errors!
7878
@build.check!
7979
end
8080

81+
def mountable?
82+
deploy.mountable?
83+
end
84+
85+
def to_rack
86+
deploy.to_rack
87+
end
88+
8189
private
8290

8391
def development?

lib/ember_cli/deploy/file.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "rack"
12
require "ember_cli/errors"
23

34
module EmberCli
@@ -7,6 +8,14 @@ def initialize(app)
78
@app = app
89
end
910

11+
def mountable?
12+
true
13+
end
14+
15+
def to_rack
16+
Rack::File.new(app.dist_path.to_s)
17+
end
18+
1019
def index_html
1120
if index_file.exist?
1221
index_file.read

lib/ember_cli/route_helpers.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ def mount_ember_app(app_name, to:, **options)
1818
get("#{to}(*rest)", routing_options)
1919
end
2020

21-
dist_directory = ::EmberCli[app_name].paths.dist
21+
mount_ember_assets(app_name, to: to)
22+
end
23+
24+
def mount_ember_assets(app_name, to: "/")
25+
app = ::EmberCli[app_name]
2226

23-
mount Rack::File.new(dist_directory.to_s) => to
27+
if app.mountable?
28+
mount app.to_rack => to
29+
end
2430
end
2531
end
2632
end

spec/lib/ember_cli/app_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
require "ember-cli-rails"
22

33
describe EmberCli::App do
4+
describe "#to_rack" do
5+
it "delegates to `#deploy`" do
6+
deploy = double(to_rack: :delegated)
7+
app = EmberCli["my-app"]
8+
allow(app).to receive(:deploy).and_return(deploy)
9+
10+
to_rack = app.to_rack
11+
12+
expect(to_rack).to be :delegated
13+
end
14+
end
15+
16+
describe "#mountable?" do
17+
it "delegates to `#deploy`" do
18+
deploy = double(mountable?: :delegated)
19+
app = EmberCli["my-app"]
20+
allow(app).to receive(:deploy).and_return(deploy)
21+
22+
mountable = app.mountable?
23+
24+
expect(mountable).to be :delegated
25+
end
26+
end
27+
428
describe "#compile" do
529
it "exits with exit status of 0" do
630
passed = EmberCli["my-app"].compile

spec/lib/ember_cli/deploy/file_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
end
2323
end
2424

25+
describe "#mountable?" do
26+
it "returns true" do
27+
deploy = EmberCli::Deploy::File.new(build_app)
28+
29+
mountable = deploy.mountable?
30+
31+
expect(mountable).to be true
32+
end
33+
end
34+
35+
describe "#to_rack" do
36+
it "creates a Rack::File instance" do
37+
deploy = EmberCli::Deploy::File.new(build_app)
38+
39+
rack_app = deploy.to_rack
40+
41+
expect(rack_app).to respond_to(:call)
42+
end
43+
end
44+
2545
def create_index(directory, contents)
2646
directory.join("index.html").write(contents)
2747
end

0 commit comments

Comments
 (0)