Sha256: 4e5267579343a211a04775b8a024540ad705c5a8c914c67e086ff7f49c5afceb

Contents?: true

Size: 753 Bytes

Versions: 7

Compression:

Stored size: 753 Bytes

Contents

##
# YAML Helper 是用于加载知识层枚举的配置文件的辅助模块。

module Unidom::Common::YamlHelper

  ##
  # 从应用或者引擎的跟路径 root 加载 config/enum.yml 中的内容到 config 中。
  def self.load_enum(config: nil, root: nil)

    enum_yaml_path = root.join 'config', 'enum.yml'
    raise ArgumentError.new "The file #{enum_yaml_path} does not exist." unless enum_yaml_path.exist?

    unless config.respond_to? :enum
      config.class_eval do
        attr_accessor :enum
      end
    end
    config.enum = {} if config.enum.nil?

    enum_definitions = YAML.load File.read(enum_yaml_path)
    config.enum.merge! enum_definitions['enum'] if enum_definitions.present?&&enum_definitions['enum'].present?

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
unidom-common-2.1.2 lib/unidom/common/yaml_helper.rb
unidom-common-2.1.1 lib/unidom/common/yaml_helper.rb
unidom-common-2.1 lib/unidom/common/yaml_helper.rb
unidom-common-2.0 lib/unidom/common/yaml_helper.rb
unidom-common-1.11 lib/unidom/common/yaml_helper.rb
unidom-common-1.10 lib/unidom/common/yaml_helper.rb
unidom-common-1.9.2 lib/unidom/common/yaml_helper.rb