Class: Remotenv::Adapters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/remotenv/adapters/base.rb

Direct Known Subclasses

Http

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, options = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/remotenv/adapters/base.rb', line 10

def initialize(uri, options = {})
  @uri = uri
  @options = options
  @data = {}
  @content = nil
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/remotenv/adapters/base.rb', line 7

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/remotenv/adapters/base.rb', line 8

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/remotenv/adapters/base.rb', line 6

def uri
  @uri
end

Instance Method Details

#after_loadObject



33
34
# File 'lib/remotenv/adapters/base.rb', line 33

def after_load
end

#apply_environmentObject



40
41
42
43
44
45
46
47
# File 'lib/remotenv/adapters/base.rb', line 40

def apply_environment
  Remotenv.logger.debug("Applying environment variables")
  @data = Dotenv::Parser.call(@content)
  Remotenv.logger.debug("ENV: #{@data.keys.join(', ')}")
  @data.each do |key, value|
    ENV[key] ||= value
  end
end

#before_loadObject



26
27
# File 'lib/remotenv/adapters/base.rb', line 26

def before_load
end

#get(key) ⇒ Object



49
50
51
# File 'lib/remotenv/adapters/base.rb', line 49

def get(key)
  @data[key]
end

#loadObject



29
30
31
# File 'lib/remotenv/adapters/base.rb', line 29

def load
  raise "Remotenv::Adapter::Base should not be used directly"
end

#load!Object



17
18
19
20
21
22
23
24
# File 'lib/remotenv/adapters/base.rb', line 17

def load!
  Remotenv.logger.debug("Adapter: #{self.class.name}")
  before_load
  load
  after_load
  apply_environment
  set_refresh_timestamp
end

#set_refresh_timestampObject



36
37
38
# File 'lib/remotenv/adapters/base.rb', line 36

def set_refresh_timestamp
  ENV['REMOTENV_REFRESHED_AT'] = Time.now.to_s
end