Class: Anmo::ApplicationDataStore

Inherits:
Object
  • Object
show all
Defined in:
lib/anmo/application.rb

Constant Summary collapse

TTL =
1000000

Class Method Summary collapse

Class Method Details

.clear_objectsObject



31
32
33
# File 'lib/anmo/application.rb', line 31

def self.clear_objects
  server.delete("objects")
end

.clear_requestsObject



35
36
37
# File 'lib/anmo/application.rb', line 35

def self.clear_requests
  server.delete("requests")
end

.find(path, query_string) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/anmo/application.rb', line 39

def self.find(path, query_string)
  self.objects.each do |object|
    object_path = object["path"].gsub(/(\?.*)$/, "")
    if path == object_path
      object_query_string = Rack::Utils.parse_query(object["path"].gsub(/(.*?)\?/, ""))

      if query_string == object_query_string
        p object
        return object
      end
    end
  end
end

.insert_object(object) ⇒ Object



19
20
21
22
23
# File 'lib/anmo/application.rb', line 19

def self.insert_object object
  all_objects = objects
  all_objects.unshift(object)
  server.set("objects", JSON.dump(all_objects), TTL)
end

.objectsObject



7
8
9
10
11
# File 'lib/anmo/application.rb', line 7

def self.objects
  cached_objects = server.get("objects")
  return JSON.load(cached_objects) if cached_objects
  []
end

.requestsObject



13
14
15
16
17
# File 'lib/anmo/application.rb', line 13

def self.requests
  cached_requests = server.get("requests")
  return JSON.load(cached_requests) if cached_requests
  []
end

.save_request(request) ⇒ Object



25
26
27
28
29
# File 'lib/anmo/application.rb', line 25

def self.save_request request
  all_requests = requests
  all_requests << request
  server.set("requests", JSON.dump(all_requests), TTL)
end