module AppStack::ConfigParser

reopen App, mixin

Public Instance Methods

load_config() click to toggle source
# File lib/app_stack/configuration.rb, line 41
def load_config
  info 'load configuration file from:', @conf_file
  Configuration.new(@conf_file)
end
parse_export_groups!() click to toggle source

rubocop:disable LineLength, MethodLength

# File lib/app_stack/configuration.rb, line 59
def parse_export_groups!
  @export_groups = { 'default' => [] }
  config.export.each do |exp|
    case
    when exp.is_a?(Hash) then @export_groups.merge!(exp)
    when exp.is_a?(String) then @export_groups['default'] << exp
    else fail ParseError, "Error on #{@conf_file}, wrong type for export: '#{exp.inspect}'"
    end
  end

  # validate export file list format
  @export_groups.each do |gname, list|
    fail ParseError, "Error on #{@conf_file}, group name must be an String, not #{gname}" unless gname.is_a?(String)
    fail ParseError, "Error on #{@conf_file} export group #{gname}, export files should be defined as a Array of String, #{list} is not an array." unless list.is_a?(Array)
    list.each { |f| fail ParseError, "Error on #{@conf_file} export group #{gname}, export files should be defined as a Array of string, not #{f}" unless f.is_a?(String) }
  end
  @export_groups
end
validate_config!() click to toggle source
# File lib/app_stack/configuration.rb, line 46
def validate_config!
  parse_export_groups!
  @sync_list = parse_stack_list!('sync')
  info 'load sync list as', @sync_list
  @import_list = parse_stack_list!('import')
  info 'load import list as', @import_list
  @render_list = parse_render_list!

  # rubocop:disable LineLength
  config.exclude.each { |f| fail "Error on #{@conf_file} for exclude settings, #{f.inspect} is not a String" unless f.is_a?(String) }
end

Private Instance Methods

parse_render_list!() click to toggle source
# File lib/app_stack/configuration.rb, line 102
def parse_render_list!
  hlist = {}
  config.render.each do |exp|
    fail ParseError, "Error on #{@conf_file}, render group, #{exp.inspect} is not a Hash" unless exp.is_a?(Hash)
    exp.each do |app, list|
      fail ParseError, "Error on #{@conf_file}, #{list_type} group, #{app} is not a String" unless app.is_a?(String)
      fail ParseError, "Error on #{@conf_file}, render for #{app}, #{list.inspect} is not a Hash" unless list.is_a?(Hash)
      list.each do |fr, to|
        fail ParseError, "Error on #{@conf_file}, render for #{app}, #{fr.inspect} is not a String" unless fr.is_a?(String)
        fail ParseError, "Error on #{@conf_file}, render for #{app}, #{to.inspect} is not a String" unless to.is_a?(String)
      end
    end
    hlist.merge! exp
  end
  hlist
end
parse_stack_list!(list_type) click to toggle source

rubocop:disable CyclomaticComplexity

# File lib/app_stack/configuration.rb, line 81
def parse_stack_list!(list_type)
  hlist = {}
  config.send(list_type.to_sym).each do |exp|
    case
    when exp.is_a?(String) then # exp is the app name with default group
      hlist[exp] = ['default']
    when exp.is_a?(Hash)
      exp.each do |app, list|
        fail ParseError, "Error on #{@conf_file}, #{list_type} group, #{app} is not a String" unless app.is_a?(String)
        fail ParseError, "Error on #{@conf_file}, #{list_type} group, #{list} is not a Array" unless list.is_a?(Array)
        list.each do |g|
          fail ParseError, "Error on #{@conf_file}, #{app} in #{list_type}, #{g} should be an String (file group) or a Hash (file mapping)" unless g.is_a?(Hash) || g.is_a?(String)
        end
      end
      hlist.merge!(exp)
    else fail ParseError, "Error on #{@conf_file}, #{list_type} group, should be an array of String or Hash." unless list.is_a?(Array)
    end
  end
  hlist
end