Sha256: 912922c5a28dfde17d6443ed22c41d471385cece5b6870ba025045958ff522d6

Contents?: true

Size: 1.71 KB

Versions: 12

Compression:

Stored size: 1.71 KB

Contents

module Percy
  module Capybara
    class Client
      module Builds
        def current_build(options = {})
          return if !enabled?  # Silently skip if the client is disabled.
          @current_build ||= client.create_build(client.config.repo, options)
        end
        alias_method :initialize_build, :current_build

        def upload_missing_build_resources(build_resources)
          # Upload any missing build resources.
          new_build_resources = current_build['data'] &&
            current_build['data']['relationships'] &&
            current_build['data']['relationships']['missing-resources'] &&
            current_build['data']['relationships']['missing-resources']['data']
          return 0 if !new_build_resources

          new_build_resources.each_with_index do |missing_resource, i|
            sha = missing_resource['id']
            resource = build_resources.find { |r| r.sha == sha }
            content = resource.content || File.read(resource.path)
            client.upload_resource(current_build['data']['id'], content)
            if i % 50 == 0
              puts "[percy] Uploading #{i+1} of #{new_build_resources.length} new resources..."
            end
          end
          new_build_resources.length
        end

        def build_initialized?
          !!@current_build
        end

        def finalize_current_build
          return if !enabled?  # Silently skip if the client is disabled.
          if !build_initialized?
            raise Percy::Capybara::Client::BuildNotInitializedError.new(
              'Failed to finalize build because no build has been initialized.')
          end
          client.finalize_build(current_build['data']['id'])
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
percy-capybara-0.4.12 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.11 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.10 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.9 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.8 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.7 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.6 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.5 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.4 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.3 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.2 lib/percy/capybara/client/builds.rb
percy-capybara-0.4.1 lib/percy/capybara/client/builds.rb