Sha256: 2f7143b81dcaefb7c1e63da759bda96ab9a381dfced4bd44d8cdbd3dbf7cf36b

Contents?: true

Size: 988 Bytes

Versions: 5

Compression:

Stored size: 988 Bytes

Contents

module ReportsKit
  module Reports
    module FilterTypes
      class Base
        attr_accessor :settings, :properties

        def initialize(settings, properties)
          self.settings = settings || {}
          self.properties = properties
        end

        def apply_filter(records)
          return records unless valid?
          records = records.joins(joins) if joins.present?
          return records if value.blank? && !is_a?(FilterTypes::Boolean)
          apply_conditions(records)
        end

        def default_criteria
          self.class::DEFAULT_CRITERIA
        end

        private

        def apply_conditions(_records)
          raise NotImplementedError
        end

        def criteria
          properties[:criteria]
        end

        def value
          criteria[:value]
        end

        def joins
          settings[:joins]
        end

        def column
          settings[:column] || properties[:key]
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reports_kit-0.1.0 lib/reports_kit/reports/filter_types/base.rb
reports_kit-0.0.4 lib/reports_kit/reports/filter_types/base.rb
reports_kit-0.0.3 lib/reports_kit/reports/filter_types/base.rb
reports_kit-0.0.2 lib/reports_kit/reports/filter_types/base.rb
reports_kit-0.0.1 lib/reports_kit/reports/filter_types/base.rb