/
adapter.rb
64 lines (61 loc) · 1.69 KB
/
adapter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module Lotus
module Model
module Config
# Configuration for the adapter
#
# Lotus::Model has its own global configuration that can be manipulated
# via `Lotus::Model.configure`.
#
# New adapter configuration can be registered via `Lotus::Model.adapter`.
#
# @see Lotus::Model.adapter
#
# @example
# require 'lotus/model'
#
# Lotus::Model.configure do
# adapter :sql, 'postgres://localhost/database'
# end
#
# Registered adapters can be retrieved via `Lotus::Model.adapters`
#
# @see Lotus::Model.adapters
#
# @example
# Lotus::Model.adapter[:sql]
# # => Lotus::Model::Config::Adapter(name: :sql, uri: 'postgres://localhost/database')
#
# @since 0.2.0
class Adapter
# @return name [Symbol] the unique adapter name
#
# @since 0.2.0
#
# @see Lotus::Config::Adapter#name
attr_reader :name
# @return uri [String] the adapter URI
#
# @since 0.2.0
#
# @see Lotus::Config::Adapter#uri
attr_reader :uri
# @return default [TrueClass, FalseClass] Decide if the adapter
# is used by default
#
# @since 0.2.0
#
# @see Lotus::Config::Adapter#default
attr_reader :default
# Initialize an adapter configuration instance
#
# @return [Lotus::Model::Config::Adapter] a new apdapter configuration's
# instance
#
# @since 0.2.0
def initialize(name, uri, default = false)
@name, @uri, @default = name, uri, default
end
end
end
end
end