Class: ObjectifiedEnvironments::DataProvider

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

Instance Method Summary collapse

Instance Method Details

#host_nameObject



28
29
30
31
32
33
34
35
36
# File 'lib/objectified_environments/data_provider.rb', line 28

def host_name
  @host_name ||= begin
    candidates = [ host_name_from_hostname_command, socket_gethostname ]
    candidates = candidates.map { |c| normalize_hostname(c) }.compact
    candidates[0] || :none
  end

  @host_name unless @host_name == :none
end

#rails_envObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/objectified_environments/data_provider.rb', line 5

def rails_env
  @rails_env ||= begin
    out = Rails.env || ''
    if out.strip.length == 0
      raise "#{self.name}: There appears to be no Rails.env set; I can't create an objectified environment for you. I don't know why this would happen. Rails.env is: #{Rails.env.inspect}"
    end

    out
  end
end

#user_nameObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/objectified_environments/data_provider.rb', line 16

def user_name
  @user_name ||= begin
    require 'etc'

    candidates = [ Etc.getlogin, ENV['USER'], ENV['LOGNAME'], ENV['USERNAME'] ]
    candidates = candidates.map { |c| c.strip unless (! c) || c.strip.length == 0 }.compact
    candidates[0] || :none
  end

  @user_name unless @user_name == :none
end