Sha256: d090947f841f251876ae0eed7b25c935b7b0309ccaf944cf471c4487a7079784

Contents?: true

Size: 875 Bytes

Versions: 2

Compression:

Stored size: 875 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}.  Are you sure you are in a project with ufo setup?"
        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

2 entries across 2 versions & 1 rubygems

Version Path
ufo-1.7.1 lib/ufo/settings.rb
ufo-1.7.0 lib/ufo/settings.rb