module Bizside::ItamaeConfAccessorMixin
各フェーズで itamae_conf
メソッド経由でアクセスできるようにするための ユーティリティ。node メソッドと同様。
Public Instance Methods
itamae_conf(*args)
click to toggle source
# File lib/bizside/itamae_conf.rb, line 140 def itamae_conf(*args) if args.nil? || (args.is_a?(Array) && args[0].is_a?(Symbol) || args[0].nil?) itamae_conf_sub(itamae_conf_factory.conf, args) elsif args.is_a?(Array) && args[0].is_a?(String) itamae_conf_sub(itamae_conf_factory.conf, args[0].split('.').map{|s| s.to_sym}) else raise 'unsupported argument type' end end
itamae_conf_factory()
click to toggle source
必要に応じて上書き
# File lib/bizside/itamae_conf.rb, line 136 def itamae_conf_factory Bizside::ItamaeConf.instance end
set_itamae_conf(key, value)
click to toggle source
itamae_conf
に値をセットします。
安易な上書きを避けるため、既存値が存在する場合は OverWriteError としています。
簡単化のため、シンボル指定(set_itamae_conf
(:a, :b, …, value))はサポートしていません (itamae_conf
と違って)。
# File lib/bizside/itamae_conf.rb, line 156 def set_itamae_conf(key, value) raise 'まだ用途が定まっていないので、使用不可です。' unless Bizside.env == 'test' set_itamae_conf_sub(itamae_conf_factory.conf, key.split('.'), key, value) end
Private Instance Methods
itamae_conf_sub(data, args)
click to toggle source
# File lib/bizside/itamae_conf.rb, line 163 def itamae_conf_sub(data, args) if args.size == 0 data elsif data.is_a?(Hash) itamae_conf_sub(data[args[0].to_s], args.drop(1)) else nil end end
set_itamae_conf_sub(hash, args, key, value)
click to toggle source
ここで key は単にエラーメッセージ用途
# File lib/bizside/itamae_conf.rb, line 174 def set_itamae_conf_sub(hash, args, key, value) arg0 = args[0] if args.size == 1 raise ItamaeConf::OverWriteError.new("duplicate on #{key}") if hash[arg0] hash[arg0] = value else hash[arg0] = {} if hash[arg0].nil? set_itamae_conf_sub(hash[arg0], args.drop(1), key, value) end end