cachai 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3b3122123c313c1e0eb4c2fd843ce971e484018
4
- data.tar.gz: f35981e1eedad868a4efc3c19d59b9f0c9444521
3
+ metadata.gz: 234339e799e8d9dcf93b45c1c9263a99cc1ff02c
4
+ data.tar.gz: 98ad064f8d146f20e974855ad269ef99c4b24c5b
5
5
  SHA512:
6
- metadata.gz: df702d38631c267a6d141f8a3680e1fc2b6f565597288c4ae455ae704bf701bc38ea25bcfdafb4e361ab60e54ecda1f885f7de7809e1d3ac7b41bc189e6cb134
7
- data.tar.gz: a20dcf35e6547d2e45d9a843cd222cbb111df210b36e117d9d906b908f6ff928409cc24f7ce9a5f25373b1d2c726e23f012431b4044779487faf411007ead185
6
+ metadata.gz: 20bfee40c5964d4e8df84e2e349028d17a8b12684841376654a4967d5f814b99379973dcc9457b1e9eca65208ce7829f49ad4b42d72b15e04219cbf4e7d22c42
7
+ data.tar.gz: e7f6c090387caa5a6450a07d288c120d8ce4e0d4250a62d44a6aa037319d5384627c3c3239c83dd07cd841bae4a5a786705cf3ca083af026f22faafbb6ebb135
data/cachai.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "cachai"
7
- spec.version = '0.0.3'
7
+ spec.version = '0.0.4'
8
8
  spec.authors = ["Tomás Pollak"]
9
9
  spec.email = ["tomas@forkhq.com"]
10
10
  spec.description = %q{Middleware for embedabble comments.}
data/lib/cachai.rb CHANGED
@@ -80,7 +80,7 @@ module Cachai
80
80
  :author_ip => request.ip
81
81
  }
82
82
 
83
- post = Post.find_by_path!(data['path'])
83
+ post = Post.find_or_create_by_path(data['path'])
84
84
  response = Response.create!(attrs.merge(:post_id => post.id))
85
85
 
86
86
  @redis.del(redis_key(data['path']))
@@ -123,8 +123,13 @@ module Cachai
123
123
  key = redis_key(path)
124
124
  unless json_list = @redis.get(key)
125
125
  puts "Not cached. Getting from DB: #{path}"
126
- post = Post.find_by_path!(path)
127
- json_list = get_and_sort_comments_for(post).to_json
126
+
127
+ if post = Post.find_by_path(path)
128
+ json_list = get_and_sort_comments_for(post).to_json
129
+ else
130
+ json_list = '[]'
131
+ end
132
+
128
133
  @redis.set(key, json_list)
129
134
  @redis.expire(key, 60 * 60) # one hour
130
135
  end
@@ -136,9 +141,6 @@ module Cachai
136
141
  top_level = post.responses.comment.top_level
137
142
  nested = post.responses.comment.nested
138
143
 
139
- puts top_level.count
140
- puts nested.count
141
-
142
144
  top_level.each_with_index do |comment, i|
143
145
  obj = comment.as_json
144
146
  children = nested.select do |nested|
data/lib/models.rb CHANGED
@@ -29,6 +29,10 @@ module Cachai
29
29
 
30
30
  validates_presence_of :path
31
31
  validates_uniqueness_of :path
32
+
33
+ def self.find_or_create_by_path(path)
34
+ find_by_path(path) || create({:path => path})
35
+ end
32
36
  end
33
37
 
34
38
  class Response < ActiveRecord::Base
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
@@ -148,9 +148,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.4.5
151
+ rubygems_version: 2.2.0
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Middleware for embedabble comments.
155
155
  test_files:
156
156
  - test/app_test.rb
157
+ has_rdoc: