Sha256: d8479e8138eb0b6292f509c0c45686efde02f74e8f2947703f49cb1cfe00c695

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require 'thor'
require 'yaml'

module Redmine
  module Cli
    class << self

      def config
        begin
          generic_conf '.redmine'
        rescue Errno::ENOENT
          puts "You need to create the file .redmine in your home with your username, password and url"
          exit 1
        end
      end

      def cache
        begin
          generic_conf '.redmine_cache'
        rescue Errno::ENOENT
          @cache = Thor::CoreExt::HashWithIndifferentAccess.new
        end
      end

      private

      def generic_conf(config_file)
        # Using Ruby Magic(tm) to get the caller's function name to use for
        # setting up instance variables/accessors for generic config files.
        config_name = caller[0][/`.*'/][1..-2]

        if !File.file? config_file
          config_file = File.expand_path "~/#{config_file}"
        end

        contents = YAML.load_file config_file
        if contents
          config ||= Thor::CoreExt::HashWithIndifferentAccess.new(YAML.load_file(config_file))
        else
          config ||= Thor::CoreExt::HashWithIndifferentAccess.new
        end
        self.instance_variable_set("@#{config_name}", config)
      end


    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
redmine-cli-0.1.5 lib/redmine-cli/config.rb
redmine-cli-0.1.4 lib/redmine-cli/config.rb