class Percy::Capybara::Bedrock::Loader
Constants
- RESOURCE_PATHS
- SKIP_RESOURCE_BASENAMES
- SKIP_RESOURCE_EXTENSIONS
- SKIP_RESOURCE_PATHS
Attributes
base_url[R]
web_root[R]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# File lib/percy/capybara/bedrock/loader.rb, line 70 def initialize(options = {}) # @web_root should point to <bedrock>/web @web_root = options[:web_root] @base_url = options[:base_url] || '/' raise ArgumentError, '@web_root is required' if @web_root.nil? || @web_root == '' unless Pathname.new(@web_root).absolute? raise ArgumentError, "@web_root needs to be an absolute path. Received: #{@web_root}" end unless Dir.exist?(@web_root) raise ArgumentError, "@web_root provided was not found. Received: #{@web_root}" end super end
Public Instance Methods
_resources_from_dir(root_dir, base_url: '/')
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 95 def _resources_from_dir(root_dir, base_url: '/') resources = [] resource_dirs = RESOURCE_PATHS.map do |resource_path| root_dir + resource_path end _find_files(resource_dirs).each do |path| next if skip?(path: path) # Replace the @web_root with the base_url to generate the resource_url resource_url = _uri_join(base_url, path.sub(root_dir.to_s, '')) sha = Digest::SHA256.hexdigest(File.read(path)) resources << Percy::Client::Resource.new(resource_url, sha: sha, path: path) end resources end
build_resources()
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 90 def build_resources _resources_from_dir(@web_root, base_url: @base_url) end
skip?(path:)
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 114 def skip?(path:) skip_extension?(path: path) || skip_basename?(path: path) || skip_path?(path: path) || skip_file_size?(path: path) end
skip_basename?(path:)
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 125 def skip_basename?(path:) SKIP_RESOURCE_BASENAMES.include?(File.basename(path)) end
skip_extension?(path:)
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 121 def skip_extension?(path:) SKIP_RESOURCE_EXTENSIONS.include?(File.extname(path)) end
skip_file_size?(path:)
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 133 def skip_file_size?(path:) File.size(path) > MAX_FILESIZE_BYTES end
skip_path?(path:)
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 129 def skip_path?(path:) SKIP_RESOURCE_PATHS.any? { |skip| path.include?(skip) } end
snapshot_resources()
click to toggle source
# File lib/percy/capybara/bedrock/loader.rb, line 86 def snapshot_resources [root_html_resource] end