Sha256: 7c90291e9563f816b6dffa2684fcaa0c2d725ece71f96465624058bd879e0c60

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require 'configatron'

module Riemann
  module Babbler

    module Options

      @@configatron = configatron

      def opts
        @@configatron
      end

      #@return
      def merge_config(file)
        config_from_file = if File.exist?(file)
                             YAML.load_file(file).to_hash
                           else
                             log :error, "Can't load config file #{file}"
                             Hash.new
                           end
        config_default   = opts.to_hash
        result_config    = config_default.deep_merge(config_from_file)
        opts.configure_from_hash(result_config)
      end

      # return configatron from hash
      def opts_reset!(hash)
        opts.reset!
        opts.configure_from_hash(hash)
      end

      # return string tw_cli_3
      def name_to_underscore(name = 'Riemann::Babbler::Plugin::TwCli_3')
        name.split('::').last.gsub(/(\p{Lower})(\p{Upper})/, "\\1_\\2").downcase
      end

      # return string Riemann::Babbler::Plugin::TwCli_3
      def underscore_to_name(name = 'tw_cli_3', parent = 'Riemann::Babbler::Plugin')
        parent + '::'  + name.to_s.split('_').map { |part|
          if part.to_i != 0
            "_#{part}"
          else
            part.capitalize
          end
        }.join('')
      end

      def self.included(base)
        Configatron.log.level = Logger::FATAL
        base.extend(self)
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
riemann-babbler-2.0.0pre11 lib/riemann/babbler/options.rb
riemann-babbler-2.0.0pre10 lib/riemann/babbler/options.rb
riemann-babbler-2.0.0pre9 lib/riemann/babbler/options.rb