Class: Vanity::Connection
- Inherits:
-
Object
- Object
- Vanity::Connection
- Defined in:
- lib/vanity/connection.rb
Defined Under Namespace
Classes: InvalidSpecification, Specification
Constant Summary collapse
- DEFAULT_SPECIFICATION =
{ adapter: "redis" }
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#specification ⇒ Object
readonly
Returns the value of attribute specification.
Instance Method Summary collapse
-
#connected? ⇒ Boolean
Returns true if connection is open.
-
#disconnect! ⇒ Object
Closes the current connection.
-
#initialize(specification = nil) ⇒ Connection
constructor
With no argument, uses the connection specified in the configuration file, or defaults to Redis on localhost, port 6379.
Constructor Details
#initialize(specification = nil) ⇒ Connection
With no argument, uses the connection specified in the configuration file, or defaults to Redis on localhost, port 6379. If the argument is a string, it is processed as a URL. If the argument is a Hash, and contains a key ‘:redis` the value is used as a redis connection. Otherwise, the argument is a hash and specifies the adapter name and any additional options understood by that adapter (as with config/vanity.yml). Note that all keys are expected to be symbols.
33 34 35 36 37 |
# File 'lib/vanity/connection.rb', line 33 def initialize(specification = nil) @specification = Specification.new(specification || DEFAULT_SPECIFICATION).to_h @adapter = setup_connection(@specification) if Autoconnect.playground_should_autoconnect? end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/vanity/connection.rb', line 7 def adapter @adapter end |
#specification ⇒ Object (readonly)
Returns the value of attribute specification.
7 8 9 |
# File 'lib/vanity/connection.rb', line 7 def specification @specification end |
Instance Method Details
#connected? ⇒ Boolean
Returns true if connection is open.
49 50 51 |
# File 'lib/vanity/connection.rb', line 49 def connected? @adapter && @adapter.active? end |
#disconnect! ⇒ Object
Closes the current connection.
42 43 44 |
# File 'lib/vanity/connection.rb', line 42 def disconnect! @adapter.disconnect! if connected? end |