Sha256: 768d174e1f3c978af8b9c2d6ee369974f0842564d37784e9dd738e94f2ad1f60

Contents?: true

Size: 651 Bytes

Versions: 47

Compression:

Stored size: 651 Bytes

Contents

require 'yaml'
require 'cl/helper'

class Cl
  class Config
    class Files < Struct.new(:name)
      include Merge

      PATHS = %w(
        ~/.%s.yml
        ./.%s.yml
      )

      def load
        configs.any? ? symbolize(merge(*configs)) : {}
      end

      private

        def configs
          @configs ||= paths.map { |path| YAML.load_file(path) || {} }
        end

        def paths
          paths = PATHS.map { |path| File.expand_path(path % name) }
          paths.select { |path| File.exist?(path) }
        end

        def symbolize(hash)
          hash.map { |key, value| [key.to_sym, value] }.to_h
        end
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
travis-cl-1.2.4 lib/cl/config/files.rb
cl-1.2.4 lib/cl/config/files.rb
cl-1.2.3 lib/cl/config/files.rb
cl-1.2.2 lib/cl/config/files.rb
cl-1.2.1 lib/cl/config/files.rb
cl-1.2.0 lib/cl/config/files.rb
cl-1.1.5 lib/cl/config/files.rb
cl-1.1.4 lib/cl/config/files.rb
cl-1.1.3 lib/cl/config/files.rb
cl-1.1.2 lib/cl/config/files.rb
cl-1.1.1 lib/cl/config/files.rb
cl-1.1.0 lib/cl/config/files.rb
cl-1.0.5 lib/cl/config/files.rb
cl-1.0.4 lib/cl/config/files.rb
cl-1.0.3 lib/cl/config/files.rb
cl-1.0.2 lib/cl/config/files.rb
cl-1.0.1 lib/cl/config/files.rb
cl-1.0.0 lib/cl/config/files.rb
cl-0.1.28 lib/cl/config/files.rb
cl-0.1.27 lib/cl/config/files.rb