Module: Vanity::Adapters

Defined in:
lib/vanity/adapters/mock_adapter.rb,
lib/vanity/adapters/redis_adapter.rb,
lib/vanity/adapters/mongodb_adapter.rb,
lib/vanity/adapters/abstract_adapter.rb,
lib/vanity/adapters/active_record_adapter.rb

Defined Under Namespace

Classes: AbstractAdapter, ActiveRecordAdapter, MockAdapter, MongodbAdapter, RedisAdapter

Class Method Summary collapse

Class Method Details

.active_record_connection(spec) ⇒ Object

Creates new ActiveRecord connection and returns ActiveRecordAdapter.



5
6
7
8
# File 'lib/vanity/adapters/active_record_adapter.rb', line 5

def active_record_connection(spec)
  require 'active_record'
  ActiveRecordAdapter.new(spec)
end

.establish_connection(spec) ⇒ Object

Creates new connection to underlying datastore and returns suitable adapter (adapter object extends AbstractAdapter and wraps the connection). Vanity.playgroup.establish_connection uses this.

Since:

  • 1.4.0



10
11
12
13
# File 'lib/vanity/adapters/abstract_adapter.rb', line 10

def establish_connection(spec)
  adapter_method = "#{spec[:adapter]}_connection"
  send adapter_method, spec
end

.mock_connection(spec) ⇒ Object

Creates and returns new MockAdapter.

Since:

  • 1.4.0



7
8
9
# File 'lib/vanity/adapters/mock_adapter.rb', line 7

def mock_connection(spec)
  MockAdapter.new(spec)
end

.mongo_connection(spec) ⇒ Object Also known as: mongodb_connection

Creates new connection to MongoDB and returns MongoAdapter.

Since:

  • 1.4.0



7
8
9
10
# File 'lib/vanity/adapters/mongodb_adapter.rb', line 7

def mongo_connection(spec)
  require "mongo"
  MongodbAdapter.new(spec)
end

.redis_connection(spec) ⇒ Object

Creates new connection to Redis and returns RedisAdapter.

Since:

  • 1.4.0



7
8
9
10
# File 'lib/vanity/adapters/redis_adapter.rb', line 7

def redis_connection(spec)
  require "redis/namespace"
  RedisAdapter.new(spec)
end