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.
-
#loader ⇒ Object
Returns the value of attribute loader.
-
#loader_options ⇒ Object
Returns the value of attribute loader_options.
-
#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 ⇒ 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.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/percy/capybara/client.rb', line 25 def initialize( = {}) @failed = false @client = [:client] || Percy.client @enabled = [:enabled] = [:loader_options] || {} return unless defined?(Rails) @sprockets_environment = [:sprockets_environment] || Rails.application.assets = [:sprockets_options] || Rails.application.config.assets end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
18 19 20 |
# File 'lib/percy/capybara/client.rb', line 18 def client @client end |
#loader ⇒ Object
Returns the value of attribute loader.
22 23 24 |
# File 'lib/percy/capybara/client.rb', line 22 def loader @loader end |
#loader_options ⇒ Object
Returns the value of attribute loader_options.
23 24 25 |
# File 'lib/percy/capybara/client.rb', line 23 def end |
#sprockets_environment ⇒ Object
Returns the value of attribute sprockets_environment.
20 21 22 |
# File 'lib/percy/capybara/client.rb', line 20 def sprockets_environment @sprockets_environment end |
#sprockets_options ⇒ Object
Returns the value of attribute sprockets_options.
21 22 23 |
# File 'lib/percy/capybara/client.rb', line 21 def end |
Instance Method Details
#disable! ⇒ Object
62 63 64 |
# File 'lib/percy/capybara/client.rb', line 62 def disable! @enabled = false end |
#enabled? ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/percy/capybara/client.rb', line 49 def enabled? return @enabled unless @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 @enabled = false end |
#failed? ⇒ Boolean
81 82 83 |
# File 'lib/percy/capybara/client.rb', line 81 def failed? !!@failed end |
#initialize_loader(options = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/percy/capybara/client.rb', line 85 def initialize_loader( = {}) = .merge() is_sprockets = sprockets_environment && if is_sprockets [:sprockets_environment] = sprockets_environment [:sprockets_options] = end if loader case loader when :filesystem Percy.logger.debug { 'Using filesystem_loader to discover assets.' } Percy::::Loaders::FilesystemLoader.new() when :native Percy.logger.debug { 'Using native_loader to discover assets (slow).' } Percy::::Loaders::NativeLoader.new() when :ember_cli_rails Percy.logger.debug { 'Using ember_cli_rails_loader to discover assets.' } mounted_apps = .delete(:mounted_apps) Percy::::Loaders::EmberCliRailsLoader.new(mounted_apps, ) else Percy.logger.debug { 'Using a custom loader to discover assets.' } loader.new() end elsif is_sprockets Percy.logger.debug { 'Using sprockets_loader to discover assets.' } Percy::::Loaders::SprocketsLoader.new() else unless @warned_about_native_loader Percy.logger.warn \ '[DEPRECATED] The native_loader is deprecated and will be opt-in in a future ' \ 'release. You should move to the faster, more reliable filesystem_loader. See the ' \ 'docs for Non-Rails frameworks: https://percy.io/docs/clients/ruby/capybara ' @warned_about_native_loader = true end 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
40 41 42 43 44 45 46 47 |
# File 'lib/percy/capybara/client.rb', line 40 def required_environment_variables_set? if !ENV['PERCY_TOKEN'].nil? && ENV['PERCY_PROJECT'].nil? raise '[percy] It looks like you were trying to enable Percy because PERCY_TOKEN ' \ 'is set, but you are missing the PERCY_PROJECT environment variable!' end !(ENV['PERCY_PROJECT'].nil? || ENV['PERCY_TOKEN'].nil?) end |
#rescue_connection_failures ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/percy/capybara/client.rb', line 66 def rescue_connection_failures raise ArgumentError, 'block is required' unless block_given? begin yield 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 |