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
-
#required_environment_variables_set? ⇒ Boolean
Check that environment variables required for Percy::Client are set.
- #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 31 32 |
# File 'lib/percy/capybara/client.rb', line 22 def initialize( = {}) @failed = false @client = [:client] || Percy.client @enabled = [:enabled] if defined?(Rails) @sprockets_environment = [:sprockets_environment] || Rails.application.assets = [: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 end |
Instance Method Details
#disable! ⇒ Object
52 53 54 |
# File 'lib/percy/capybara/client.rb', line 52 def disable! @enabled = false end |
#enabled? ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/percy/capybara/client.rb', line 39 def enabled? return @enabled if !@enabled.nil? # Disable if PERCY_ENABLE is set to 0 return @enabled = false if ENV['PERCY_ENABLE'] == '0' # Enable if required environment variables are set return @enabled = true if required_environment_variables_set? # Disable otherwise return @enabled = false end |
#failed? ⇒ Boolean
71 72 73 |
# File 'lib/percy/capybara/client.rb', line 71 def failed? return !!@failed end |
#initialize_loader(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/percy/capybara/client.rb', line 75 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::::Loaders::SprocketsLoader.new() else Percy.logger.debug { 'Using native_loader to discover assets (slower).' } Percy::::Loaders::NativeLoader.new() end end |
#required_environment_variables_set? ⇒ Boolean
Check that environment variables required for Percy::Client are set
35 36 37 |
# File 'lib/percy/capybara/client.rb', line 35 def required_environment_variables_set? !(ENV['PERCY_PROJECT'].nil? || ENV['PERCY_TOKEN'].nil?) end |
#rescue_connection_failures(&block) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/percy/capybara/client.rb', line 56 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 |