module Hario::Filterable

Constants

HARIO_APPLY_TYPES

Attributes

hario_attributes_list[R]

Public Instance Methods

apply_filters(filters) click to toggle source
# File lib/hario.rb, line 21
def apply_filters(filters)
  fp = FilterParser.new(filters, self)

  fp.where_clauses.reduce(joins(fp.join_clause), &:where)
end
apply_pluck(pluck) click to toggle source
# File lib/hario.rb, line 27
def apply_pluck(pluck)
  pp = PluckParser.new(pluck, self)

  results = joins(pp.join_clause).hash_pluck(*pp.pluck_clause)

  remove_local_table_prefix(results)
end
hario_attributes(types, only: nil, except: nil) click to toggle source
# File lib/hario.rb, line 43
def hario_attributes(types, only: nil, except: nil)
  @hario_attributes_list ||= {}
  Array.wrap(types).each do |t|
    raise_if_not_hario_type!(t)
    @hario_attributes_list[t] =
      { only: Array.wrap(only), except: Array.wrap(except) }
  end
end
hash_pluck(*keys) click to toggle source
# File lib/hario.rb, line 39
def hash_pluck(*keys)
  pluck(*keys).map{ |vals| Hash[keys.zip(Array(vals))] }
end
remove_local_table_prefix(results) click to toggle source
# File lib/hario.rb, line 35
def remove_local_table_prefix(results)
  results.map{ |r| r.transform_keys!{ |k| k.gsub(/^#{table_name}\./, '') } }
end

Private Instance Methods

raise_if_not_hario_type!(type) click to toggle source
# File lib/hario.rb, line 53
def raise_if_not_hario_type!(type)
  unless HARIO_APPLY_TYPES.include?(type)
    raise ArgumentError, "#{type} is not one of " \
      "#{HARIO_APPLY_TYPES.map(&:inspect).join(', ')}"
  end
end