Class: Bizside::ItamaeConfSub

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

Overview

itamae_conf をテストするため、 singleton 以前のクラスを定義

TODO: HanaitaConf と類似していますが HanaitaConf は obsolete 予定なので 敢えて refactoring はやっていません。

Direct Known Subclasses

ItamaeConf

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeItamaeConfSub

Returns a new instance of ItamaeConfSub.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bizside/itamae_conf.rb', line 40

def initialize
  for conf_file in self.class.conf_files do
    if File.exist?(conf_file)
      @_conf ||= {}
      hash = YAML.load(ERB.new(File.read(conf_file)).result)

      case conf_file
      # itamae.yml スペシャルロジック。ROLE必須。
      when /itamae.yml$/
        role = ENV['ROLE']
        next if role.nil? || role.empty?
        hash = hash[role]

      # database.yml スペシャルロジック。例:
      #
      # database.yml::  RAILS_ENV.adapter
      # ↓::             ↓
      # itamae_conf::   db.adapter
      when /database.yml$/
        partial = hash[Bizside.env]
        hash = {'db' => partial.dup} if partial
      end
      deep_merge!(@_conf, hash) if hash
    else
      $stderr.printf("WARN: %s does NOT exist.\n", conf_file)
    end
  end
end

Class Method Details

.conf_filesObject

base..derived の順



12
13
14
15
16
17
18
19
20
21
# File 'lib/bizside/itamae_conf.rb', line 12

def conf_files
  if ENV['ITAMAE_CONFS']
    ENV['ITAMAE_CONFS'].split
  else
    result = ['/etc/bizside/hanaita.yml']
    add_yml(result, 'itamae.yml')
    add_yml(result, 'database.yml')
    result
  end
end

Instance Method Details

#confObject



69
70
71
# File 'lib/bizside/itamae_conf.rb', line 69

def conf
  @_conf
end