Class: Percy::Capybara::Loaders::FilesystemLoader

Inherits:
BaseLoader
  • Object
show all
Defined in:
lib/percy/capybara/loaders/filesystem_loader.rb

Overview

Resource loader that looks for resources in the specified folder.

Constant Summary

Constants inherited from BaseLoader

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

Instance Attribute Summary

Attributes inherited from BaseLoader

#page

Instance Method Summary collapse

Methods inherited from BaseLoader

#_find_files, #_resources_from_dir, #_uri_join

Constructor Details

#initialize(options = {}) ⇒ FilesystemLoader

Returns a new instance of FilesystemLoader.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/percy/capybara/loaders/filesystem_loader.rb', line 11

def initialize(options = {})
  # @assets_dir should point to a _compiled_ static assets directory, not source assets.
  @assets_dir = options[:assets_dir]
  @base_url = options[:base_url] || '/'

  raise ArgumentError, 'assets_dir is required' if @assets_dir.nil? || @assets_dir == ''
  unless Pathname.new(@assets_dir).absolute?
    raise ArgumentError, "assets_dir needs to be an absolute path. Received: #{@assets_dir}"
  end
  unless Dir.exist?(@assets_dir)
    raise ArgumentError, "assets_dir provided was not found. Received: #{@assets_dir}"
  end

  super
end

Instance Method Details

#build_resourcesObject



31
32
33
# File 'lib/percy/capybara/loaders/filesystem_loader.rb', line 31

def build_resources
  _resources_from_dir(@assets_dir, base_url: @base_url)
end

#snapshot_resourcesObject



27
28
29
# File 'lib/percy/capybara/loaders/filesystem_loader.rb', line 27

def snapshot_resources
  [root_html_resource]
end