Class: RemoteDatabaseCleaner::Config

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

Constant Summary collapse

DEFAULT_HOME_CONFIG =
{ :host      => nil, 
:port      => nil, 
:end_point => '/remote_database_cleaner/home/clean' }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Config

Returns a new instance of Config.



18
19
20
21
# File 'lib/remote_database_cleaner/config.rb', line 18

def initialize(attrs = {})
  attrs[:home] = update_home_config(attrs)
  super(attrs)
end

Class Method Details

.configure(configs) ⇒ Object



14
15
16
# File 'lib/remote_database_cleaner/config.rb', line 14

def self.configure(configs)
  new(configs)
end

Instance Method Details

#has_home?Boolean

Returns:

  • (Boolean)


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

def has_home?
  !home[:host].nil? && !(home[:host] == '') && !home[:end_point].nil? && !(home[:end_point] == '')
end

#home_urlObject



23
24
25
26
27
28
29
30
31
# File 'lib/remote_database_cleaner/config.rb', line 23

def home_url
  raise_no_host_error
  http = 'http://'
  if home[:port]
    "#{ http }#{ home.fetch(:host) }:#{ home.fetch(:port) }#{ home.fetch(:end_point) }"
  else
    "#{ http }#{ home.fetch(:host) }#{ home.fetch(:end_point) }"
  end
end

#raise_no_host_errorObject



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

def raise_no_host_error
  raise RemoteDatabaseCleanerConfigError.new("RemoteDatabaseCleaner.config.home[:host] can not be nil") unless has_home?
end

#to_hashObject



33
34
35
36
# File 'lib/remote_database_cleaner/config.rb', line 33

def to_hash
  raise_no_host_error
  super.merge(home_url: home_url)
end