Module: FmRest::Spyke::Model::Connection
- Extended by:
- ActiveSupport::Concern
- Included in:
- FmRest::Spyke::Model
- Defined in:
- lib/fmrest/spyke/model/connection.rb
Overview
This module provides methods for configuring the Farday connection for the model, as well as setting up the connection itself.
Class Method Summary collapse
-
.clear_fmrest_config_overlay ⇒ Object
Clears the connection settings overlay.
-
.connection ⇒ Object
Spyke override -- Defaults to
fmrest_connection
. -
.faraday(&block) ⇒ Object
Sets a block for injecting custom middleware into the Faraday connection.
- .fmrest_config ⇒ Object
-
.fmrest_config=(settings) ⇒ Object
Sets the FileMaker connection settings for the model.
-
.fmrest_config_overlay ⇒ FmRest::ConnectionSettings
The connection settings overlay if any is in use.
-
.fmrest_config_overlay=(settings) ⇒ Object
Allows overriding some connection settings in a thread-local manner.
-
.with_overlay(settings, &block) ⇒ Object
Runs a block of code in the context of the given connection settings without affecting the connection settings outside said block.
Instance Method Summary collapse
Class Method Details
.clear_fmrest_config_overlay ⇒ Object
Clears the connection settings overlay.
70 71 72 |
# File 'lib/fmrest/spyke/model/connection.rb', line 70 def Thread.current[] = nil end |
.connection ⇒ Object
Spyke override -- Defaults to fmrest_connection
98 99 100 |
# File 'lib/fmrest/spyke/model/connection.rb', line 98 def connection super || fmrest_connection end |
.faraday(&block) ⇒ Object
Sets a block for injecting custom middleware into the Faraday connection.
113 114 115 |
# File 'lib/fmrest/spyke/model/connection.rb', line 113 def faraday(&block) self.faraday_block = block end |
.fmrest_config ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/fmrest/spyke/model/connection.rb', line 21 def fmrest_config if return FmRest.default_connection_settings.merge(, skip_validation: true) end FmRest.default_connection_settings end |
.fmrest_config=(settings) ⇒ Object
Sets the FileMaker connection settings for the model.
Behaves similar to ActiveSupport's class_attribute
, so it can be
inherited and safely overwritten in subclasses.
36 37 38 39 40 41 42 43 44 |
# File 'lib/fmrest/spyke/model/connection.rb', line 36 def fmrest_config=(settings) settings = ConnectionSettings.new(settings, skip_validation: true) singleton_class.redefine_method(:fmrest_config) do = return settings.merge(, skip_validation: true) if settings end end |
.fmrest_config_overlay ⇒ FmRest::ConnectionSettings
Returns the connection settings overlay if any is in use.
60 61 62 63 64 65 66 |
# File 'lib/fmrest/spyke/model/connection.rb', line 60 def Thread.current[] || begin superclass. rescue NoMethodError nil end end |
.fmrest_config_overlay=(settings) ⇒ Object
Allows overriding some connection settings in a thread-local manner. Useful in the use case where you want to connect to the same database using different accounts (e.g. credentials provided by users in a web app context).
53 54 55 |
# File 'lib/fmrest/spyke/model/connection.rb', line 53 def (settings) Thread.current[] = settings end |
.with_overlay(settings, &block) ⇒ Object
Runs a block of code in the context of the given connection settings without affecting the connection settings outside said block.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fmrest/spyke/model/connection.rb', line 85 def (settings, &block) Fiber.new do begin self. = settings yield ensure self. end end.resume end |
Instance Method Details
#fmrest_config ⇒ Object
157 158 159 |
# File 'lib/fmrest/spyke/model/connection.rb', line 157 def fmrest_config self.class.fmrest_config end |