Sha256: a4d156e39f73edc9b473d4061a2f32111589bddfce965ca4d85d346d1c8a711b

Contents?: true

Size: 767 Bytes

Versions: 2

Compression:

Stored size: 767 Bytes

Contents

module WhoAmI
  module Function
    class LoadConfig
      include ProcParty

      def initialize(root)
        @root = root
      end

      def call
        Config.new(loaded_configuration)
      end

      private

      def loaded_configuration
        @loaded_configuration ||=
          if File.exist?(initializer_path)
            contents = YAML.load_file(initializer_path)
            deep_symbolize_hash(contents)
          else
            {}
          end
      end

      def initializer_path
        File.join(@root, "config", "who_am_i.yml")
      end

      def deep_symbolize_hash(obj)
        if obj.is_a?(Hash)
          obj.map { |k, v| [k.to_sym, deep_symbolize_hash(v)] }.to_h
        else
          obj
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
who_am_i-0.0.6 lib/who_am_i/function/load_config.rb
who_am_i-0.0.5 lib/who_am_i/function/load_config.rb