Class: Aaet::Redis
- Inherits:
-
Object
- Object
- Aaet::Redis
- Defined in:
- lib/aaet/common/redis.rb
Instance Attribute Summary collapse
-
#process ⇒ Object
Returns the value of attribute process.
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #activities ⇒ Object
- #activity_exists?(act) ⇒ Boolean
- #add_found_activity(act) ⇒ Object
- #app_crashed(boolean) ⇒ Object
- #del_list(list) ⇒ Object
- #found_activities ⇒ Object
- #found_activity_exists?(act) ⇒ Boolean
- #get_list(list) ⇒ Object
- #hget(key, field) ⇒ Object
- #hincr(key, field) ⇒ Object
- #hset(key, field, value) ⇒ Object
-
#initialize(process) ⇒ Redis
constructor
A new instance of Redis.
- #list_includes_applitools_value(list, value) ⇒ Object
- #list_includes_value(list, value) ⇒ Object
- #lpop(list) ⇒ Object
- #remove_activity(activity) ⇒ Object
- #symbolize(obj) ⇒ Object
- #update_activity_count(act) ⇒ Object
- #update_applitools(list, body) ⇒ Object
- #update_list(list, body) ⇒ Object
Constructor Details
#initialize(process) ⇒ Redis
Returns a new instance of Redis.
6 7 8 9 10 |
# File 'lib/aaet/common/redis.rb', line 6 def initialize process self.redis = Redic.new self.process = process update_list("crashed", false) end |
Instance Attribute Details
#process ⇒ Object
Returns the value of attribute process.
4 5 6 |
# File 'lib/aaet/common/redis.rb', line 4 def process @process end |
#redis ⇒ Object
Returns the value of attribute redis.
4 5 6 |
# File 'lib/aaet/common/redis.rb', line 4 def redis @redis end |
Instance Method Details
#activities ⇒ Object
32 33 34 |
# File 'lib/aaet/common/redis.rb', line 32 def activities redis.call("LRANGE", "activities", 0, -1) end |
#activity_exists?(act) ⇒ Boolean
24 25 26 |
# File 'lib/aaet/common/redis.rb', line 24 def activity_exists? act activities.any? { |a| a.include? act } end |
#add_found_activity(act) ⇒ Object
44 45 46 |
# File 'lib/aaet/common/redis.rb', line 44 def add_found_activity act redis.call "LPUSH", "found_activities-#{process}", act end |
#app_crashed(boolean) ⇒ Object
88 89 90 |
# File 'lib/aaet/common/redis.rb', line 88 def app_crashed boolean redis.call "LPUSH", "crashed-#{process}", boolean end |
#del_list(list) ⇒ Object
12 13 14 |
# File 'lib/aaet/common/redis.rb', line 12 def del_list list redis.call "DEL", "#{list}-#{process}" rescue nil end |
#found_activities ⇒ Object
36 37 38 |
# File 'lib/aaet/common/redis.rb', line 36 def found_activities redis.call("LRANGE", "found_activities-#{process}", 0, -1) end |
#found_activity_exists?(act) ⇒ Boolean
40 41 42 |
# File 'lib/aaet/common/redis.rb', line 40 def found_activity_exists? act found_activities.any? { |a| a.include? act } end |
#get_list(list) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/aaet/common/redis.rb', line 60 def get_list list redis_list = redis.call("LRANGE", "#{list}-#{process}", 0, -1).map { |x| JSON.parse(x) }.uniq.flatten rescue [] unless redis_list.empty? redis_list = symbolize(redis_list) end redis_list end |
#hget(key, field) ⇒ Object
104 105 106 |
# File 'lib/aaet/common/redis.rb', line 104 def hget(key, field) redis.call("HGET", "#{key}-#{process}", field) end |
#hincr(key, field) ⇒ Object
96 97 98 |
# File 'lib/aaet/common/redis.rb', line 96 def hincr(key, field) redis.call("HINCRBY", "#{key}-#{process}", field, 1) end |
#hset(key, field, value) ⇒ Object
100 101 102 |
# File 'lib/aaet/common/redis.rb', line 100 def hset(key, field, value) redis.call("HSET", "#{key}-#{process}", field, value) end |
#list_includes_applitools_value(list, value) ⇒ Object
84 85 86 |
# File 'lib/aaet/common/redis.rb', line 84 def list_includes_applitools_value list, value redis.call("LRANGE", list, 0, -1).any? { |a| a.include? value } end |
#list_includes_value(list, value) ⇒ Object
80 81 82 |
# File 'lib/aaet/common/redis.rb', line 80 def list_includes_value list, value redis.call("LRANGE", "#{list}-#{process}", 0, -1).any? { |a| a.include? value } end |
#lpop(list) ⇒ Object
92 93 94 |
# File 'lib/aaet/common/redis.rb', line 92 def lpop list redis.call "LPOP", "#{list}-#{process}" end |
#remove_activity(activity) ⇒ Object
28 29 30 |
# File 'lib/aaet/common/redis.rb', line 28 def remove_activity activity redis.call "LREM", "activities", -1, activity end |
#symbolize(obj) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/aaet/common/redis.rb', line 68 def symbolize(obj) return obj.reduce({}) do |memo, (k, v)| memo.tap { |m| m[k.to_sym] = symbolize(v) } end if obj.is_a? Hash return obj.reduce([]) do |memo, v| memo << symbolize(v); memo end if obj.is_a? Array obj end |
#update_activity_count(act) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aaet/common/redis.rb', line 48 def update_activity_count act unless found_activity_exists? act checkmark = "\u2713" puts "" puts "\nNew Activity Found! #{checkmark}".green add_found_activity act remaining = (activities.count - found_activities.count) puts "Remaining Activities: #{remaining}\n" puts "" end end |
#update_applitools(list, body) ⇒ Object
16 17 18 |
# File 'lib/aaet/common/redis.rb', line 16 def update_applitools list, body redis.call "LPUSH", list, JSON.generate(body) end |
#update_list(list, body) ⇒ Object
20 21 22 |
# File 'lib/aaet/common/redis.rb', line 20 def update_list list, body redis.call "LPUSH", "#{list}-#{process}", JSON.generate(body) end |