Sha256: bcb3c1561ff9ab9301b0edb4f83a78d8493392175c69ea747fad628a511e31f5

Contents?: true

Size: 867 Bytes

Versions: 3

Compression:

Stored size: 867 Bytes

Contents

module ReportsKit
  module Reports
    class ModelSettings
      attr_accessor :model_class, :model_configuration_type, :key

      def initialize(model_class, model_configuration_type, key)
        self.model_class = model_class
        self.model_configuration_type = model_configuration_type
        self.key = key
      end

      def settings_from_model
        return {} if model_configuration.blank?
        config_hashes = model_configuration.public_send(model_configuration_type)
        return {} if config_hashes.blank?
        config_hash = config_hashes.find do |hash|
          hash[:key] == key
        end
        config_hash || {}
      end

      private

      def model_configuration
        return unless model_class && model_class.respond_to?(:reports_kit_configuration)
        model_class.reports_kit_configuration
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reports_kit-0.7.1 lib/reports_kit/reports/model_settings.rb
reports_kit-0.7.0 lib/reports_kit/reports/model_settings.rb
reports_kit-0.5.0 lib/reports_kit/reports/model_settings.rb