Sha256: 47072ef70dea3c38f96e4791f3615358386f8c6aee34808969cf9e7a943c294f

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require "ember-cli/railtie" if defined?(Rails)

module EmberCLI
  extend self

  autoload :App,           "ember-cli/app"
  autoload :Configuration, "ember-cli/configuration"
  autoload :ViewHelpers,   "ember-cli/view_helpers"
  autoload :Helpers,       "ember-cli/helpers"

  def configure
    yield configuration
  end

  def configuration
    Configuration.instance
  end

  def prepare!
    @prepared ||= begin
      Rails.configuration.assets.paths << root.join("assets").to_s
      at_exit{ cleanup }
      true
    end
  end

  def enable!
    prepare!

    Rails.application.instance_eval do
      singleton_class.instance_eval do
        alias_method :call_without_ember_cli, :call
      end

      def call(env)
        @_ember_cli_enabled ||= begin
          EmberCLI.compile!
          EmberCLI.run! if Rails.env.development?
          true
        end

        call_without_ember_cli(env)
      end
    end
  end

  def run!
    prepare!
    each_app &:run
  end

  def compile!
    prepare!
    each_app &:compile
  end

  def stop!
    each_app &:stop
  end

  def root
    @root ||= Rails.root.join("tmp", "ember-cli-#{uid}")
  end

  private

  def uid
    @uid ||= SecureRandom.uuid
  end

  def cleanup
    root.rmtree if root.exist?
  end

  def each_app
    configuration.apps.each{ |name, app| yield app }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ember-cli-rails-0.0.7 lib/ember-cli-rails.rb
ember-cli-rails-0.0.6 lib/ember-cli-rails.rb