Sha256: 0d379e6d54cf492e82c75bfa60bd83d7ae6d601f6423a99b71ad63b517dc4385

Contents?: true

Size: 823 Bytes

Versions: 8

Compression:

Stored size: 823 Bytes

Contents

require 'yaml'

module Ufo
  class Settings
    def initialize(project_root='.')
      @project_root = project_root
    end

    # data contains the settings.yml config.  The order or precedence for settings
    # is the project ufo/settings.yml and then the ~/.ufo/settings.yml.
    def data
      return @data if @data

      if File.exist?(settings_path)
        @data = YAML.load_file(settings_path)
        @data = user_settings.merge(@data)
      else
        puts "ERROR: No settings file at #{settings_path}"
        puts "Please create a settings file via: ufo init"
        exit 1
      end
    end

    def user_settings
      path = "#{ENV['HOME']}/.ufo/settings.yml"
      File.exist?(path) ? YAML.load_file(path) : {}
    end

    def settings_path
      "#{@project_root}/ufo/settings.yml"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ufo-1.6.2 lib/ufo/settings.rb
ufo-1.6.1 lib/ufo/settings.rb
ufo-1.6.0 lib/ufo/settings.rb
ufo-1.5.0 lib/ufo/settings.rb
ufo-1.2.0 lib/ufo/settings.rb
ufo-1.1.0 lib/ufo/settings.rb
ufo-1.0.1 lib/ufo/settings.rb
ufo-1.0.0 lib/ufo/settings.rb