Sha256: 25fa10c2e32def041ae6bfe6f7578068944f889c0eab71e7b43feded21394014

Contents?: true

Size: 740 Bytes

Versions: 2

Compression:

Stored size: 740 Bytes

Contents

module Bidu
  module Mercy
    class ReportConfig
      attr_accessor :config

      delegate :[], :[]=, :merge, to: :config

      def initialize(config)
        @config = config
      end

      def build(parameters)
        params = slice_parameters(parameters)
        report_class.new(config.merge(params))
      end

      private

      def type
        self[:type] ||= :error
      end

      def report_class
        return type if type.is_a?(Class)
        @report_class ||= Bidu::Mercy::Report.const_get(type.to_s.camelize)
      end

      def slice_parameters(parameters)
        parameters.slice(*allowed_parameters)
      end

      def allowed_parameters
        report_class::ALLOWED_PARAMETERS
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mercy-1.3.0 lib/bidu/mercy/report_config.rb
bidu-mercy-1.3.0 lib/bidu/mercy/report_config.rb