Sha256: af0e777c19938cb90005dd7da855ec52abd31f35ad7161a40b7534b59c2cbaa7

Contents?: true

Size: 1.42 KB

Versions: 40

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

40 entries across 40 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/options.rb
riemann-babbler-2.8.4 lib/riemann/babbler/options.rb
riemann-babbler-2.8.3 lib/riemann/babbler/options.rb
riemann-babbler-2.8.2 lib/riemann/babbler/options.rb
riemann-babbler-2.8.1 lib/riemann/babbler/options.rb
riemann-babbler-2.8.0 lib/riemann/babbler/options.rb
riemann-babbler-2.6.0 lib/riemann/babbler/options.rb
riemann-babbler-2.5.9 lib/riemann/babbler/options.rb
riemann-babbler-2.5.8 lib/riemann/babbler/options.rb
riemann-babbler-2.5.7 lib/riemann/babbler/options.rb
riemann-babbler-2.5.6 lib/riemann/babbler/options.rb
riemann-babbler-2.5.5 lib/riemann/babbler/options.rb
riemann-babbler-2.5.4 lib/riemann/babbler/options.rb
riemann-babbler-2.5.3 lib/riemann/babbler/options.rb
riemann-babbler-2.5.2 lib/riemann/babbler/options.rb
riemann-babbler-2.5.1 lib/riemann/babbler/options.rb
riemann-babbler-2.5.0 lib/riemann/babbler/options.rb
riemann-babbler-2.1.5 lib/riemann/babbler/options.rb
riemann-babbler-2.1.4 lib/riemann/babbler/options.rb
riemann-babbler-2.1.3.2 lib/riemann/babbler/options.rb