Module: TerrapopConfigurationModule

Included in:
TerrapopConfiguration
Defined in:
app/models/terrapop_configuration.rb

Constant Summary collapse

ENVIRONMENTS =
"environments"
APPLICATION =
"application"
COUNTRIES =
"countries"
SETTINGS =
"settings"

Class Method Summary collapse

Class Method Details

.beforeObject



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
# File 'app/models/terrapop_configuration.rb', line 8

def self.before

  unless defined? @@configuration
    str = File.open(Rails.root.to_s + "/config/terrapop.yml", 'r') { |f| f.read }
    str = ERB.new(str).result
    @@configuration = YAML.load(str)
  end

  unless @@configuration.dig(APPLICATION, COUNTRIES).nil?
    if @@configuration[APPLICATION][COUNTRIES][0] == :all
      @@configuration[APPLICATION][COUNTRIES] = Country.order(:short_name).pluck(:short_name)
    end
  end

  if defined? ENV['SERVER_NAME']
    unless ENV['SERVER_NAME'].nil?
      #$stderr.puts "ServerName: #{ENV['SERVER_NAME']}"
      # this area will be arrived upon ONLY in the WebApp part of TP
      # we need to set/update a TerrapopSettings object with our current hostname
      # which is found in ENV['SERVER_NAME']
      begin
        setting = TerrapopSetting.where(name: 'server_name').first
        setting = TerrapopSetting.new if setting.nil?

        # the following line is a workaroud to a known bug in Rails 4.0 4.1
        # they are going to introduce the bugfix in Rails 4.2
        # if you stumble upon this line of code and Rails is 4.2 or more
        # please remove the following line
        setting.data_will_change!
        # end of story, thanks

        setting.data = {'value' => ENV['SERVER_NAME']}
        setting.name = 'server_name'
        setting.save
      rescue

      end
    end
  end

end