Module: Bhf::ConfigParser
- Defined in:
- lib/bhf/config_parser.rb
Class Method Summary collapse
- .get_config_array(array, dir) ⇒ Object
- .load_yml(suffix = nil) ⇒ Object
- .parse(roles_array, area = nil) ⇒ Object
- .roles_yml(roles = nil, area = nil) ⇒ Object
Class Method Details
.get_config_array(array, dir) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/bhf/config_parser.rb', line 41 def get_config_array(array, dir) array.each_with_object({'pages' => []}) do |r, account_roles| pages = load_yml("#{dir}/#{r}")['pages'] account_roles['pages'] += pages if pages end end |
.load_yml(suffix = nil) ⇒ Object
77 78 79 |
# File 'lib/bhf/config_parser.rb', line 77 def load_yml(suffix = nil) YAML::load(IO.read("config/bhf#{suffix}.yml")) end |
.parse(roles_array, area = nil) ⇒ Object
6 7 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 |
# File 'lib/bhf/config_parser.rb', line 6 def parse(roles_array, area = nil) roles_config = roles_yml(roles_array, area) if Bhf::Engine.config.abstract_config.any? tmp_pages = get_config_array(Bhf::Engine.config.abstract_config, '/abstract')['pages'] abstract_platform_config = tmp_pages.each_with_object({}) do |abstract_pages, hash| abstract_pages.each do |abstract_page| abstract_page[1].each do |abstract_platform| hash.merge!(abstract_platform) end end end roles_config['pages'].each_with_index do |pages, i_1| pages.each_pair do |key_1, page| page.each_with_index do |platform, i_2| platform.each_pair do |key_2, value| abstract_platform_key = if value.to_h['extend_abstract'] value.to_h['extend_abstract'] elsif abstract_platform_config[key_2] key_2 end next unless abstract_platform_key roles_config['pages'][i_1][key_1][i_2][key_2] = abstract_platform_config[abstract_platform_key].deep_merge(value.to_h) end end end end end return Bhf::Settings.new(roles_config) end |
.roles_yml(roles = nil, area = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bhf/config_parser.rb', line 48 def roles_yml(roles = nil, area = nil) area_dir = "/#{area}" if area.present? if roles.is_a?(String) load_yml("#{area_dir}/#{roles}") elsif roles.is_a?(Array) files = get_config_array(roles, area_dir) # find the same pages and merge them merged_files = {'pages' => []} files['pages'].each do |pages| merged = false pages.each_pair do |key, page| merged_files['pages'].each do |m_page| if m_page.include?(key) merged = true m_page[key] = m_page[key] + page end end end if !merged merged_files['pages'] << pages end end merged_files else load_yml end end |