Class: Symphonia::ModelFilters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/symphonia/model_filters/base.rb

Direct Known Subclasses

BooleanFilter, DateFilter, IntegerFilter, StringFilter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, query, options = {}) ⇒ Base

Returns a new instance of Base.

Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/symphonia/model_filters/base.rb', line 9

def initialize(attribute, query, options = {})
  if attribute.is_a? String
    ActiveSupport::Deprecation.warn("name as argument is no longer supported - use Attribute")
    @name = attribute
  else
    @name = attribute.name
    @attribute = attribute
  end
  @options = options
  @query = query
  @operator = 'eq'
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



4
5
6
# File 'lib/symphonia/model_filters/base.rb', line 4

def caption
  @caption
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/symphonia/model_filters/base.rb', line 4

def name
  @name
end

#operatorObject

Returns the value of attribute operator.



4
5
6
# File 'lib/symphonia/model_filters/base.rb', line 4

def operator
  @operator
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/symphonia/model_filters/base.rb', line 4

def options
  @options
end

#queryObject (readonly)

Returns the value of attribute query.



4
5
6
# File 'lib/symphonia/model_filters/base.rb', line 4

def query
  @query
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/symphonia/model_filters/base.rb', line 4

def type
  @type
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/symphonia/model_filters/base.rb', line 4

def value
  @value
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/symphonia/model_filters/base.rb', line 35

def active?
  !!query.active_filters[name]
end

#apply(_scope) ⇒ Object



70
71
72
# File 'lib/symphonia/model_filters/base.rb', line 70

def apply(_scope)
  Rails.logger.debug("Apply filter #{name} '#{operator}' #{value}")
end

#form_field(_c) ⇒ Object

Raises:

  • (NotImplementError)


27
28
29
# File 'lib/symphonia/model_filters/base.rb', line 27

def form_field(_c)
  raise NotImplementError
end

#inspectObject



31
32
33
# File 'lib/symphonia/model_filters/base.rb', line 31

def inspect
  "#<#{self.class.name} name='#{name}' caption='#{caption}' options=#{@options.inspect}>"
end