nomo 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nomo/model.rb +28 -22
- data/lib/nomo/page.rb +8 -9
- data/lib/nomo/record.rb +40 -0
- data/lib/nomo/version.rb +1 -1
- data/lib/nomo.rb +1 -0
- metadata +7 -6
data/lib/nomo/model.rb
CHANGED
@@ -4,51 +4,57 @@ module Nomo
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
def has_page(name, options = {})
|
7
|
-
|
8
|
-
|
7
|
+
page = :"#{name}_page"
|
8
|
+
modify_page = :"modify_#{page}"
|
9
9
|
|
10
|
-
define_method
|
10
|
+
define_method page do
|
11
11
|
@nomo_pages ||= {}
|
12
12
|
@nomo_pages[name] ||= Nomo::Page.new(self, name, options)
|
13
13
|
end
|
14
14
|
|
15
|
-
define_method
|
16
|
-
page = send(
|
17
|
-
page.modify
|
15
|
+
define_method modify_page do
|
16
|
+
page = send(page)
|
17
|
+
page.modify
|
18
18
|
end
|
19
19
|
|
20
|
-
after_save
|
21
|
-
after_touch
|
22
|
-
after_destroy
|
20
|
+
after_save modify_page
|
21
|
+
after_touch modify_page
|
22
|
+
after_destroy modify_page
|
23
23
|
end
|
24
24
|
|
25
25
|
def modifies_page(association, name)
|
26
|
-
|
26
|
+
association_page = :"#{association}_#{name}_page"
|
27
|
+
modify_association_page = :"modify_#{association_page}"
|
27
28
|
|
28
|
-
define_method
|
29
|
-
|
30
|
-
|
29
|
+
define_method association_page do
|
30
|
+
@nomo_pages ||= {}
|
31
|
+
@nomo_pages["#{association}/#{name}"] ||= Nomo::Page.new({ type: association, id: send(:"#{association}_id") }, name, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method modify_association_page do
|
35
|
+
page = send(association_page)
|
36
|
+
page.modify
|
31
37
|
end
|
32
38
|
|
33
|
-
after_save
|
34
|
-
after_touch
|
35
|
-
after_destroy
|
39
|
+
after_save modify_association_page
|
40
|
+
after_touch modify_association_page
|
41
|
+
after_destroy modify_association_page
|
36
42
|
end
|
37
43
|
|
38
44
|
def modifies_pages(association, name)
|
39
|
-
|
45
|
+
modify_association_pages = :"modify_#{association}_#{name}_pages"
|
40
46
|
|
41
|
-
define_method
|
47
|
+
define_method modify_association_pages do
|
42
48
|
Nomo.redis.multi do
|
43
49
|
for record in send(association)
|
44
|
-
record.send(:"modify_#{name}_page
|
50
|
+
record.send(:"modify_#{name}_page")
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
48
54
|
|
49
|
-
after_save
|
50
|
-
after_touch
|
51
|
-
after_destroy
|
55
|
+
after_save modify_association_pages
|
56
|
+
after_touch modify_association_pages
|
57
|
+
after_destroy modify_association_pages
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
data/lib/nomo/page.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
1
|
module Nomo
|
2
2
|
class Page
|
3
|
-
attr_reader :record
|
4
3
|
attr_reader :name
|
5
4
|
|
6
|
-
def initialize(
|
7
|
-
@record =
|
5
|
+
def initialize(record_or_hash, name, options = {})
|
6
|
+
@record = Nomo::Record.new(record_or_hash)
|
8
7
|
@name = name
|
9
8
|
@options = options
|
10
9
|
end
|
11
10
|
|
12
11
|
def etag
|
13
|
-
@etag ||= Digest::MD5.hexdigest(
|
12
|
+
@etag ||= Digest::MD5.hexdigest("#{key}/#{last_modified}")
|
14
13
|
end
|
15
14
|
|
16
15
|
def last_modified
|
17
|
-
@last_modified ||= Time.parse(redis.get(key) || record.updated_at.to_s).utc
|
16
|
+
@last_modified ||= Time.parse(redis.get(key) || @record.updated_at.to_s).utc
|
18
17
|
end
|
19
18
|
|
20
|
-
def modify
|
19
|
+
def modify
|
21
20
|
@etag = nil
|
22
21
|
@last_modified = Time.now.utc
|
23
22
|
|
24
23
|
redis.set(key, @last_modified)
|
25
|
-
redis.publish
|
24
|
+
redis.publish('updates', key)
|
26
25
|
end
|
27
26
|
|
28
27
|
def cache_key
|
29
|
-
|
28
|
+
"#{key}/#{etag}"
|
30
29
|
end
|
31
30
|
|
32
31
|
def key
|
33
|
-
@
|
32
|
+
"#{@record.table}/#{@record.id}/#{name}"
|
34
33
|
end
|
35
34
|
|
36
35
|
def realtime?
|
data/lib/nomo/record.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Nomo
|
2
|
+
class Record
|
3
|
+
def initialize(record_or_hash)
|
4
|
+
@record_or_hash = record_or_hash
|
5
|
+
end
|
6
|
+
|
7
|
+
def table
|
8
|
+
if @record_or_hash.is_a?(Hash)
|
9
|
+
@record_or_hash[:type].to_s.tableize
|
10
|
+
else
|
11
|
+
@record_or_hash.class.to_s.tableize
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def id
|
16
|
+
if @record_or_hash.is_a?(Hash)
|
17
|
+
@record_or_hash[:id]
|
18
|
+
else
|
19
|
+
@record_or_hash.id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def updated_at
|
24
|
+
record.updated_at
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def record
|
29
|
+
if @record_or_hash.is_a?(Hash)
|
30
|
+
@record_or_hash = model.find(@record_or_hash[:id])
|
31
|
+
end
|
32
|
+
|
33
|
+
@record_or_hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def model
|
37
|
+
Object.const_get(@record_or_hash[:type].to_s.camelize)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/nomo/version.rb
CHANGED
data/lib/nomo.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70174565056280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70174565056280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: redis-namespace
|
27
|
-
requirement: &
|
27
|
+
requirement: &70174565055380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70174565055380
|
36
36
|
description: 304 Not Modified Headers made easy.
|
37
37
|
email:
|
38
38
|
- sausman@stackd.com
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/nomo/model.rb
|
52
52
|
- lib/nomo/page.rb
|
53
53
|
- lib/nomo/rails/engine.rb
|
54
|
+
- lib/nomo/record.rb
|
54
55
|
- lib/nomo/version.rb
|
55
56
|
- nomo.gemspec
|
56
57
|
- vendor/assets/javascripts/nomo.js.coffee.erb
|