Sha256: 9f032ac47121fb3d73a97bc245c01c1c8fde8c07c37712d39b5842e6754da997

Contents?: true

Size: 870 Bytes

Versions: 10

Compression:

Stored size: 870 Bytes

Contents

module Avo
  class Filter
    attr_accessor :name
    attr_accessor :component
    attr_accessor :default

    @@default = nil

    def initialize
      @name ||= 'Filter'
      @component ||= 'boolean-filter'
      @default ||= ''
    end

    def render_response
      {
        id: id,
        name: name,
        options: options,
        component: component,
        default: default_value,
        filter_class: self.class.to_s,
      }
    end

    def apply_query(request, query, value)
      value.symbolize_keys! if value.is_a? Hash

      self.apply(request, query, value)
    end

    def id
      self.class.name.underscore.gsub('/', '_')
    end

    # These methods helps us set a default value in the testing environment
    def default_value
      @@default || default
    end

    def self.set_default(value)
      @@default = value
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
avo-0.4.2 lib/avo/app/filter.rb
avo-0.4.1 lib/avo/app/filter.rb
avo-0.3.2 lib/avo/app/filter.rb
avo-0.3.1 lib/avo/app/filter.rb
avo-0.2.5 lib/avo/app/filter.rb
avo-0.2.4 lib/avo/app/filter.rb
avo-0.2.3 lib/avo/app/filter.rb
avo-0.2.2 lib/avo/app/filter.rb
avo-0.2.1 lib/avo/app/filter.rb
avo-0.2.0 lib/avo/app/filter.rb