nomo 0.0.24 → 0.0.25

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.
Files changed (4) hide show
  1. data/lib/nomo.rb +26 -6
  2. data/lib/nomo/model.rb +23 -32
  3. data/lib/nomo/version.rb +1 -1
  4. metadata +6 -6
@@ -54,13 +54,13 @@ module Nomo
54
54
  end
55
55
 
56
56
  ##
57
- # Default options for Nomo::Model methods
58
- #
59
- # Accepts:
60
- # 1. A Nomo::Model options Hash
61
- #
62
57
  # Example:
63
- # { after_commit: { unless: lambda {|record| record.previous_changes.empty? } } }
58
+ # after_commit: {
59
+ # if: lambda {|record| record.previous_changes.any? },
60
+ # unless: :destroyed?
61
+ # }
62
+ #
63
+ # Used by Nomo::Model and Nomo::Page
64
64
  attr_writer :default_options
65
65
 
66
66
  def default_options
@@ -72,4 +72,24 @@ module Nomo
72
72
  def logger
73
73
  @logger || ::Rails.logger
74
74
  end
75
+
76
+ def redis_multi
77
+ @redis_multi_count ||= 0
78
+
79
+ if @redis_multi_count == 0
80
+ Nomo.redis.multi
81
+ Nomo.logger.debug("(nomo) redis.multi")
82
+ end
83
+
84
+ @redis_multi_count += 1
85
+ end
86
+
87
+ def redis_exec
88
+ if @redis_multi_count == 1
89
+ Nomo.redis.exec
90
+ Nomo.logger.debug("(nomo) redis.exec")
91
+ end
92
+
93
+ @redis_multi_count -= 1
94
+ end
75
95
  end
@@ -2,10 +2,21 @@ module Nomo
2
2
  module Model
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ def save
6
+ Nomo.redis_multi
7
+ super
8
+ Nomo.redis_exec
9
+ end
10
+
11
+ def destroy
12
+ Nomo.redis_multi
13
+ super
14
+ Nomo.redis_exec
15
+ end
16
+
5
17
  module ClassMethods
6
18
  def has_page(name, options = {})
7
19
  options = Nomo.default_options.merge(options)
8
-
9
20
  page_method = :"#{name}_page"
10
21
  modify_page_method = :"modify_#{name}_page"
11
22
 
@@ -19,44 +30,24 @@ module Nomo
19
30
  page.modify
20
31
  end
21
32
 
22
- after_commit modify_page_method, (options[:after_commit] || {}) unless options[:after_commit].eql?(false)
23
- after_touch modify_page_method, (options[:after_touch] || {}) unless options[:after_touch].eql?(false)
33
+ after_commit modify_page_method, options.fetch(:after_commit, {}) unless options[:after_commit].eql?(false)
34
+ after_touch modify_page_method, options.fetch(:after_touch, {}) unless options[:after_touch].eql?(false)
35
+ before_destroy modify_page_method, options.fetch(:before_destroy, {}) unless options[:before_destroy].eql?(false)
24
36
  end
25
37
 
26
- def modifies_page(association, name, options = {})
38
+ def modifies(association, name, options = {})
27
39
  options = Nomo.default_options.merge(options)
40
+ modify_page_method = :"modify_#{association}_#{name}_page"
28
41
 
29
- association_page_method = :"#{association}_#{name}_page"
30
- modify_association_page_method = :"modify_#{association}_#{name}_page"
31
-
32
- define_method association_page_method do
33
- send(association).send(:"#{name}_page")
34
- end
35
-
36
- define_method modify_association_page_method do
37
- page = send(association_page_method)
38
- page.modify
39
- end
40
-
41
- after_commit modify_association_page_method, (options[:after_commit] || {}) unless options[:after_commit].eql?(false)
42
- after_touch modify_association_page_method, (options[:after_touch] || {}) unless options[:after_touch].eql?(false)
43
- end
44
-
45
- def modifies_pages(association, name, options = {})
46
- options = Nomo.default_options.merge(options)
47
-
48
- modify_association_pages_method = :"modify_#{association}_#{name}_pages"
49
-
50
- define_method modify_association_pages_method do
51
- Nomo.redis.multi do
52
- for record in send(association)
53
- record.send(:"modify_#{name}_page")
54
- end
42
+ define_method modify_page_method do
43
+ for record in [send(association)].flatten
44
+ record.send(:"modify_#{name}_page")
55
45
  end
56
46
  end
57
47
 
58
- after_commit modify_association_pages_method, (options[:after_commit] || {}) unless options[:after_commit].eql?(false)
59
- after_touch modify_association_pages_method, (options[:after_touch] || {}) unless options[:after_touch].eql?(false)
48
+ after_commit modify_page_method, options.fetch(:after_commit, {}) unless options[:after_commit].eql?(false)
49
+ after_touch modify_page_method, options.fetch(:after_touch, {}) unless options[:after_touch].eql?(false)
50
+ before_destroy modify_page_method, options.fetch(:before_destroy, {}) unless options[:before_destroy].eql?(false)
60
51
  end
61
52
  end
62
53
  end
@@ -1,3 +1,3 @@
1
1
  module Nomo
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.25"
3
3
  end
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.24
4
+ version: 0.0.25
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 00:00:00.000000000 Z
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70305821295820 !ruby/object:Gem::Requirement
16
+ requirement: &70278236710720 !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: *70305821295820
24
+ version_requirements: *70278236710720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis-namespace
27
- requirement: &70305821307900 !ruby/object:Gem::Requirement
27
+ requirement: &70278236965240 !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: *70305821307900
35
+ version_requirements: *70278236965240
36
36
  description: 304 Not Modified Headers made easy.
37
37
  email:
38
38
  - sausman@stackd.com