Sha256: b2bd406c775b20df7e803aee771a3c2a90de5750e04797557f24e37d2ab71479

Contents?: true

Size: 740 Bytes

Versions: 6

Compression:

Stored size: 740 Bytes

Contents

module Bidu
  module House
    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::House::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

6 entries across 6 versions & 1 rubygems

Version Path
bidu-house-1.3.0 lib/bidu/house/report_config.rb
bidu-house-1.2.0 lib/bidu/house/report_config.rb
bidu-house-1.1.0 lib/bidu/house/report_config.rb
bidu-house-1.0.0 lib/bidu/house/report_config.rb
bidu-house-0.2.1 lib/bidu/house/report_config.rb
bidu-house-0.2.0 lib/bidu/house/report_config.rb