module ActsAsExplorable::Element
Attributes
full_query[RW]
model[RW]
parameters[RW]
query_parts[RW]
query_string[RW]
query_type[RW]
Public Class Methods
build(type, query, model)
click to toggle source
This method acts as a factory to build a concrete element
@example
ActsAsExplorable::Element.build(:in, 'Zlatan in:first_name', Player)
@param type [Symbol] The element type to be build @param query [String] The query string @param model [ActiveRecord::Base] Anactive record model
@return [ActsAsExplorable::Element] A concrete element type
# File lib/acts_as_explorable/element.rb, line 22 def self.build(type, query, model) klass = Module.nesting.last.const_get('Element').const_get(type.to_s.camelize) instance = klass.new(query, model, type) rescue NameError DynamicFilter.new(query, model, type) end
new(query, model, element_type = nil)
click to toggle source
# File lib/acts_as_explorable/element.rb, line 29 def initialize(query, model, element_type = nil) query = query.to_acts_as_explorable(ActsAsExplorable.filters.keys) @type = element_type if element_type @model = model @query_string = query[:values] @query_parts = [] filter_parameters(query[:params]) after_init render if @parameters.present? end
Public Instance Methods
after_init()
click to toggle source
# File lib/acts_as_explorable/element.rb, line 42 def after_init; end
execute(query_object)
click to toggle source
# File lib/acts_as_explorable/element.rb, line 44 def execute(query_object) query_object.send(@query_type, @full_query) end
Protected Instance Methods
filter_parameters(params)
click to toggle source
# File lib/acts_as_explorable/element.rb, line 50 def filter_parameters(params) return unless params[type] @parameters = params[type].select do |f| filters.find do |e| /#{e.to_sym}(?:-\w+)?/ =~ f end end end
filters()
click to toggle source
Returns the customized filters
@return [Hash] The customized filters
# File lib/acts_as_explorable/element.rb, line 79 def filters ActsAsExplorable.filters[type] end
render()
click to toggle source
# File lib/acts_as_explorable/element.rb, line 67 def render fail "`#render` needs to be implemented for #{self.class.name}" end
table()
click to toggle source
Returns the Arel table for the current model
@return [Arel::Table] Arel table for the current model
# File lib/acts_as_explorable/element.rb, line 63 def table @model.arel_table end
type()
click to toggle source
# File lib/acts_as_explorable/element.rb, line 71 def type @type.to_sym || self.class.name.demodulize.underscore.to_sym end