Module: ChannelQueryBuilder

Defined in:
lib/query_builder/channel_query_builder.rb

Instance Method Summary collapse

Instance Method Details

#add_filter_for_category_id(q, category_id) ⇒ Object



15
16
17
# File 'lib/query_builder/channel_query_builder.rb', line 15

def add_filter_for_category_id(q, category_id)
  q.joins(:categories).where(:ems_categories_channels => {:category_id => category_id})
end

#add_filter_for_limit(q, limit) ⇒ Object

Fucntion to add a limit to a given query



11
12
13
# File 'lib/query_builder/channel_query_builder.rb', line 11

def add_filter_for_limit(q, limit)
  q.limit(limit)
end

#add_filter_for_order_by(q, column) ⇒ Object



23
24
25
# File 'lib/query_builder/channel_query_builder.rb', line 23

def add_filter_for_order_by(q, column)
  q.order column.to_sym
end

#add_filter_for_slug(q, slug) ⇒ Object



19
20
21
# File 'lib/query_builder/channel_query_builder.rb', line 19

def add_filter_for_slug(q, slug)
  q.where(:slug => slug)
end

#build_query_from_filters(q, filters) ⇒ Object



3
4
5
6
7
8
# File 'lib/query_builder/channel_query_builder.rb', line 3

def build_query_from_filters(q, filters)
  filters.each do |filter, value|
    q = method("add_filter_for_#{filter}".to_sym).call(q, value)
  end
  return q
end