Sha256: c7c6e61850638ebf209a852ee10e26342133b6ea3d62bd42156e9fc0b220743b

Contents?: true

Size: 910 Bytes

Versions: 4

Compression:

Stored size: 910 Bytes

Contents

require 'yaml'
require 'hashie'

module SlackMessaging

  class DefaultPaths
    class << self
      def config
        File.join(self.home,'.slack_messaging.yml')
      end

      def home
        ENV['HOME'] ? ENV['HOME'] : "."
      end
    end
  end

  class Config
    class << self

      def config
        config_data.to_hash
      end

      def load(path)
        load_config(path)
        config
      end

      def config_data
        @config_data ||= Hashie::Mash.new
      end
      private :config_data

      def method_missing(method, args=false)
        config_data.send(method, args)
      end
      private :method_missing

      def load_config(file)
        raise MissingConfig, "Missing configuration file: #{file}" unless File.exist?(file)
        YAML.load_file(file).each{ |key,value| config_data.assign_property(key, value) }
      end
      private :load_config

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
slack_messaging-1.3.0 lib/slack_messaging/config.rb
slack_messaging-1.2.1 lib/slack_messaging/config.rb
slack_messaging-1.2.0 lib/slack_messaging/config.rb
slack_messaging-1.1.0 lib/slack_messaging/config.rb