Class: Resque::Plugins::Stages::StagedGroupList
- Inherits:
-
Object
- Object
- Resque::Plugins::Stages::StagedGroupList
- Includes:
- RedisAccess
- Defined in:
- lib/resque/plugins/stages/staged_group_list.rb
Overview
A utility class that keeps track of all Groups and lists them.
Constant Summary
Constants included from RedisAccess
Instance Method Summary collapse
- #add_group(group) ⇒ Object
- #delete_all ⇒ Object
- #groups ⇒ Object
- #num_groups ⇒ Object
- #order_param(sort_option, current_sort, current_order) ⇒ Object
- #paginated_groups(sort_key = :description, sort_order = "asc", page_num = 1, queue_page_size = 20) ⇒ Object
- #remove_group(group) ⇒ Object
Methods included from RedisAccess
Instance Method Details
#add_group(group) ⇒ Object
43 44 45 |
# File 'lib/resque/plugins/stages/staged_group_list.rb', line 43 def add_group(group) redis.sadd list_key, group.group_id end |
#delete_all ⇒ Object
51 52 53 |
# File 'lib/resque/plugins/stages/staged_group_list.rb', line 51 def delete_all groups.each(&:delete) end |
#groups ⇒ Object
10 11 12 |
# File 'lib/resque/plugins/stages/staged_group_list.rb', line 10 def groups redis.smembers(list_key).map { |group_id| Resque::Plugins::Stages::StagedGroup.new(group_id) } end |
#num_groups ⇒ Object
39 40 41 |
# File 'lib/resque/plugins/stages/staged_group_list.rb', line 39 def num_groups groups.length end |
#order_param(sort_option, current_sort, current_order) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/resque/plugins/stages/staged_group_list.rb', line 14 def order_param(sort_option, current_sort, current_order) current_order ||= "asc" if sort_option == current_sort current_order == "asc" ? "desc" : "asc" else "asc" end end |
#paginated_groups(sort_key = :description, sort_order = "asc", page_num = 1, queue_page_size = 20) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/resque/plugins/stages/staged_group_list.rb', line 24 def paginated_groups(sort_key = :description, sort_order = "asc", page_num = 1, queue_page_size = 20) queue_page_size = queue_page_size.to_i queue_page_size = 20 if queue_page_size < 1 group_list = sorted_groups(sort_key) page_start = (page_num - 1) * queue_page_size page_start = 0 if page_start > group_list.length || page_start.negative? (sort_order == "desc" ? group_list.reverse : group_list)[page_start..(page_start + queue_page_size - 1)] end |
#remove_group(group) ⇒ Object
47 48 49 |
# File 'lib/resque/plugins/stages/staged_group_list.rb', line 47 def remove_group(group) redis.srem list_key, group.group_id end |