Sha256: 1fe1e859861eb8aac8d38686ee61413f2c9994ddf680bb3ae72ec132cf528508

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

require "rack"
require "ember_cli/errors"

module EmberCli
  module Deploy
    class File
      def initialize(app)
        @app = app
      end

      def mountable?
        true
      end

      def to_rack
        Rack::File.new(app.dist_path.to_s, rack_headers)
      end

      def index_html
        if index_file.exist?
          index_file.read
        else
          check_for_error_and_raise!
        end
      end

      private

      attr_reader :app

      def rack_headers
        config = Rails.configuration

        if config.respond_to?(:public_file_server) &&
            config.public_file_server && config.public_file_server.headers
          # Rails 5.
          config.public_file_server.headers
        elsif config.respond_to?(:static_cache_control)
          # Rails 4.2 and below.
          {
            "Cache-Control" => Rails.configuration.static_cache_control,
          }
        else
          # No specification.
          {}
        end
      end

      def check_for_error_and_raise!
        app.check_for_errors!

        raise BuildError.new <<-MSG
          EmberCLI failed to generate an `index.html` file.
        MSG
      end

      def index_file
        app.dist_path.join("index.html")
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ember-cli-rails-0.12.1 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.12.0 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.11.0 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.10.0 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.9.0 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.8.7 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.8.6 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.8.5 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.8.4 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.8.3 lib/ember_cli/deploy/file.rb
ember-cli-rails-0.8.2 lib/ember_cli/deploy/file.rb