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

+ (Object) active_record_connection(spec)

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

+ (Object) establish_connection(spec)

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

Since:

  • 1.4.0



10
11
12
13
14
15
16
17
18
# File 'lib/vanity/adapters/abstract_adapter.rb', line 10

def establish_connection(spec)
  begin
    require "vanity/adapters/#{spec[:adapter]}_adapter"
  rescue LoadError
    raise "Could not find #{spec[:adapter]} in your load path"
  end
  adapter_method = "#{spec[:adapter]}_connection"
  send adapter_method, spec
end

+ (Object) mock_connection(spec)

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

+ (Object) mongo_connection(spec) 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

+ (Object) redis_connection(spec)

Creates new connection to Redis and returns RedisAdapter.

Since:

  • 1.4.0



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

def redis_connection(spec)
  require "redis"
  fail "redis >= 2.1 is required" unless valid_redis_version?
  require "redis/namespace"
  fail "redis-namespace >= 1.1.0 is required" unless valid_redis_namespace_version?

  RedisAdapter.new(spec)
end

+ (Boolean) valid_redis_namespace_version?

Returns:

  • (Boolean)


20
21
22
# File 'lib/vanity/adapters/redis_adapter.rb', line 20

def valid_redis_namespace_version?
  Gem.loaded_specs['redis'].version >= Gem::Version.create('1.1.0')
end

+ (Boolean) valid_redis_version?

Returns:

  • (Boolean)


16
17
18
# File 'lib/vanity/adapters/redis_adapter.rb', line 16

def valid_redis_version?
  Gem.loaded_specs['redis'].version >= Gem::Version.create('2.1')
end