Class: Envconfig::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/envconfig.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Root

Returns a new instance of Root.



21
22
23
24
# File 'lib/envconfig.rb', line 21

def initialize(env)
  @env = env
  @_services = {}
end

Instance Method Details

#databaseObject



38
39
40
# File 'lib/envconfig.rb', line 38

def database
  service_for(:database, Database)
end

#database?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/envconfig.rb', line 42

def database?
  predicate_for(:database)
end

#memcachedObject



46
47
48
# File 'lib/envconfig.rb', line 46

def memcached
  service_for(:memcached, Memcached)
end

#memcached?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/envconfig.rb', line 50

def memcached?
  predicate_for(:memcached)
end

#mongodbObject



54
55
56
# File 'lib/envconfig.rb', line 54

def mongodb
  service_for(:mongodb, Mongodb)
end

#mongodb?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/envconfig.rb', line 58

def mongodb?
  predicate_for(:mongodb)
end

#redisObject



62
63
64
# File 'lib/envconfig.rb', line 62

def redis
  service_for(:redis, Redis)
end

#redis?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/envconfig.rb', line 66

def redis?
  predicate_for(:redis)
end

#smtpObject



70
71
72
# File 'lib/envconfig.rb', line 70

def smtp
  service_for(:smtp, Smtp)
end

#smtp?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/envconfig.rb', line 74

def smtp?
  predicate_for(:smtp)
end

#to_hObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/envconfig.rb', line 26

def to_h
  [
    :database,
    :memcached,
    :mongodb,
    :redis,
    :smtp,
  ].inject({}) do |hash, service|
    hash.merge!(service => public_send(service).to_h)
  end
end