Sha256: 09dd1430ff7c1f38fc9e8e2af110e82cf4307e7ad509d36d721ce37e50d1eab3

Contents?: true

Size: 932 Bytes

Versions: 26

Compression:

Stored size: 932 Bytes

Contents

require 'fitting/configuration/yaml'
require 'fitting/configuration/legacy'
require 'yaml'

module Fitting
  class Configuration
    class << self
      def craft
        if one_yaml?
          one_yaml
        elsif more_than_one_yaml?
          more_than_one_yaml
        else
          legacy
        end
      end

      def one_yaml?
        File.file?('.fitting.yml')
      end

      def more_than_one_yaml?
        !Dir['fitting/*.yml'].empty?
      end

      def one_yaml
        yaml = YAML.safe_load(File.read('.fitting.yml'))
        Fitting::Configuration::Yaml.new(yaml)
      end

      def more_than_one_yaml
        files.map do |file|
          yaml = YAML.safe_load(File.read(file))
          Fitting::Configuration::Yaml.new(yaml, file[8..-5])
        end
      end

      def legacy
        Fitting::Configuration::Legacy.new
      end

      def files
        Dir['fitting/*.yml']
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
fitting-2.18.1 lib/fitting/configuration.rb
fitting-2.18.0 lib/fitting/configuration.rb
fitting-2.17.0 lib/fitting/configuration.rb
fitting-2.16.1 lib/fitting/configuration.rb
fitting-2.16.0 lib/fitting/configuration.rb
fitting-2.15.0 lib/fitting/configuration.rb
fitting-2.14.1 lib/fitting/configuration.rb
fitting-2.14.0 lib/fitting/configuration.rb
fitting-2.13.1 lib/fitting/configuration.rb
fitting-2.13.0 lib/fitting/configuration.rb
fitting-2.12.1 lib/fitting/configuration.rb
fitting-2.12.0 lib/fitting/configuration.rb
fitting-2.11.0 lib/fitting/configuration.rb
fitting-2.10.0 lib/fitting/configuration.rb
fitting-2.9.1 lib/fitting/configuration.rb
fitting-2.9.0 lib/fitting/configuration.rb
fitting-2.8.1 lib/fitting/configuration.rb
fitting-2.8.0 lib/fitting/configuration.rb
fitting-2.7.2 lib/fitting/configuration.rb
fitting-2.7.1 lib/fitting/configuration.rb