Class: Percy::Capybara::Client
- Inherits:
-
Object
- Object
- Percy::Capybara::Client
- Defined in:
- lib/percy/capybara/client.rb,
lib/percy/capybara/client/builds.rb,
lib/percy/capybara/client/snapshots.rb
Defined Under Namespace
Modules: Builds, Snapshots Classes: BuildNotInitializedError, Error, WebMockBlockingConnectionsError
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#custom_loader ⇒ Object
Returns the value of attribute custom_loader.
-
#sprockets_environment ⇒ Object
Returns the value of attribute sprockets_environment.
-
#sprockets_options ⇒ Object
Returns the value of attribute sprockets_options.
Instance Method Summary collapse
- #disable! ⇒ Object
- #enabled? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #initialize_loader(options = {}) ⇒ Object
- #rescue_connection_failures(&block) ⇒ Object
Methods included from Snapshots
Methods included from Builds
#build_initialized?, #current_build, #finalize_current_build, #initialize_build
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 |
# File 'lib/percy/capybara/client.rb', line 22 def initialize( = {}) @client = [:client] || Percy.client @enabled = [:enabled] if defined?(Rails) @sprockets_environment = [:sprockets_environment] || Rails.application.assets @sprockets_options = [:sprockets_options] || Rails.application.config.assets end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
16 17 18 |
# File 'lib/percy/capybara/client.rb', line 16 def client @client end |
#custom_loader ⇒ Object
Returns the value of attribute custom_loader.
20 21 22 |
# File 'lib/percy/capybara/client.rb', line 20 def custom_loader @custom_loader end |
#sprockets_environment ⇒ Object
Returns the value of attribute sprockets_environment.
18 19 20 |
# File 'lib/percy/capybara/client.rb', line 18 def sprockets_environment @sprockets_environment end |
#sprockets_options ⇒ Object
Returns the value of attribute sprockets_options.
19 20 21 |
# File 'lib/percy/capybara/client.rb', line 19 def @sprockets_options end |
Instance Method Details
#disable! ⇒ Object
42 43 44 |
# File 'lib/percy/capybara/client.rb', line 42 def disable! @enabled = false end |
#enabled? ⇒ Boolean
32 33 34 35 36 37 38 39 40 |
# File 'lib/percy/capybara/client.rb', line 32 def enabled? return @enabled if !@enabled.nil? # Enable if PERCY_ENABLE=1 in local dev (allow disabling if 0). return @enabled ||= ENV['PERCY_ENABLE'] == '1' if ENV['PERCY_ENABLE'] # If in supported CI environment. @enabled ||= !Percy::Client::Environment.current_ci.nil? end |
#failed? ⇒ Boolean
61 62 63 |
# File 'lib/percy/capybara/client.rb', line 61 def failed? return !!@failed end |
#initialize_loader(options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/percy/capybara/client.rb', line 65 def initialize_loader( = {}) if custom_loader Percy.logger.debug { 'Using a custom loader to discover assets.' } custom_loader.new() elsif sprockets_environment && Percy.logger.debug { 'Using sprockets_loader to discover assets.' } [:sprockets_environment] = sprockets_environment [:sprockets_options] = Percy::Capybara::Loaders::SprocketsLoader.new() else Percy.logger.debug { 'Using native_loader to discover assets (slower).' } Percy::Capybara::Loaders::NativeLoader.new() end end |
#rescue_connection_failures(&block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/percy/capybara/client.rb', line 46 def rescue_connection_failures(&block) raise ArgumentError.new('block is required') if !block_given? begin block.call rescue Percy::Client::ServerError, # Rescue server errors. Percy::Client::PaymentRequiredError, # Rescue quota exceeded errors. Percy::Client::ConnectionFailed, # Rescue some networking errors. Percy::Client::TimeoutError => e Percy.logger.error(e) @enabled = false @failed = true nil end end |