Class: Percy::Capybara::Loaders::EmberCliRailsLoader

Inherits:
SprocketsLoader show all
Defined in:
lib/percy/capybara/loaders/ember_cli_rails_loader.rb

Constant Summary

Constants inherited from SprocketsLoader

SprocketsLoader::MAX_FILESIZE_BYTES, SprocketsLoader::SKIP_RESOURCE_EXTENSIONS

Constants inherited from BaseLoader

BaseLoader::MAX_FILESIZE_BYTES, BaseLoader::SKIP_RESOURCE_EXTENSIONS, BaseLoader::URL_REGEX

Instance Attribute Summary collapse

Attributes inherited from SprocketsLoader

#page, #sprockets_environment, #sprockets_options

Attributes inherited from BaseLoader

#page

Instance Method Summary collapse

Methods inherited from SprocketsLoader

#_asset_logical_paths, #_rails, #snapshot_resources

Methods inherited from BaseLoader

#_find_files, #_resources_from_dir, #_uri_join, #snapshot_resources

Constructor Details

#initialize(mounted_apps, options = {}) ⇒ EmberCliRailsLoader

Returns a new instance of EmberCliRailsLoader.



10
11
12
13
14
15
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 10

def initialize(mounted_apps, options = {})
  super(options)

  raise 'mounted_apps is required' unless mounted_apps
  @mounted_apps = mounted_apps
end

Instance Attribute Details

#mounted_appsObject (readonly)

Returns the value of attribute mounted_apps.



8
9
10
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 8

def mounted_apps
  @mounted_apps
end

Instance Method Details

#_dist_path_for_app(app_name) ⇒ Object



42
43
44
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 42

def _dist_path_for_app(app_name)
  _ember_cli.apps[app_name].dist_path
end

#_ember_cliObject



46
47
48
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 46

def _ember_cli
  EmberCli if defined?(EmberCli)
end

#build_resourcesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/percy/capybara/loaders/ember_cli_rails_loader.rb', line 17

def build_resources
  resources = super # adds sprockets resources first

  sprockets_resource_urls = resources.collect(&:resource_url)
  loaded_resource_urls = Set.new(sprockets_resource_urls)

  @mounted_apps.map do |app_name, mount_path|
    # full path on disk to this ember app
    # e.g. /Users/djones/Code/rails-ember-app/tmp/ember-cli/apps/frontend
    dist_path = _dist_path_for_app(app_name)

    resources_from_dir = _resources_from_dir(dist_path, base_url: mount_path)

    resources_from_dir.each do |resource|
      # avoid loading in duplicate resource_urls
      next if loaded_resource_urls.include? resource.resource_url

      resources << resource
      loaded_resource_urls << resource.resource_url
    end
  end

  resources
end