hammock 0.3.7 → 0.3.8
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.
- data/History.txt +5 -0
- data/Manifest.txt +4 -0
- data/hammock.gemspec +1 -1
- data/init.rb +3 -0
- data/lib/hammock/lambda_alias.rb +12 -0
- data/lib/hammock/lambda_composition.rb +26 -0
- data/lib/hammock/mutex.rb +45 -0
- data/lib/hammock/route_drawing_hooks.rb +1 -1
- data/lib/hammock.rb +1 -1
- metadata +5 -1
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.3.8 2009-06-05
|
2
|
+
Added LambdaAlias dep to RouteDrawingHooks, for Hammock.load_models.
|
3
|
+
Added LambdaComposition component.
|
4
|
+
|
5
|
+
|
1
6
|
== 0.3.7 2009-06-05
|
2
7
|
Rewrote hammock loading code to use nestable dependencies instead of the LoadFirst constant.
|
3
8
|
Replaced Hammock::Aliases with the Hammock:LambdaAlias component.
|
data/Manifest.txt
CHANGED
@@ -4,6 +4,7 @@ Manifest.txt
|
|
4
4
|
README.rdoc
|
5
5
|
Rakefile
|
6
6
|
hammock.gemspec
|
7
|
+
init.rb
|
7
8
|
lib/hammock.rb
|
8
9
|
lib/hammock/ajaxinate.rb
|
9
10
|
lib/hammock/callback.rb
|
@@ -14,6 +15,8 @@ lib/hammock/controller_attributes.rb
|
|
14
15
|
lib/hammock/export_scope.rb
|
15
16
|
lib/hammock/hamlink_to.rb
|
16
17
|
lib/hammock/javascript_buffer.rb
|
18
|
+
lib/hammock/lambda_alias.rb
|
19
|
+
lib/hammock/lambda_composition.rb
|
17
20
|
lib/hammock/logging.rb
|
18
21
|
lib/hammock/model_attributes.rb
|
19
22
|
lib/hammock/model_logging.rb
|
@@ -27,6 +30,7 @@ lib/hammock/monkey_patches/numeric.rb
|
|
27
30
|
lib/hammock/monkey_patches/object.rb
|
28
31
|
lib/hammock/monkey_patches/route_set.rb
|
29
32
|
lib/hammock/monkey_patches/string.rb
|
33
|
+
lib/hammock/mutex.rb
|
30
34
|
lib/hammock/overrides.rb
|
31
35
|
lib/hammock/resource_mapping_hooks.rb
|
32
36
|
lib/hammock/resource_retrieval.rb
|
data/hammock.gemspec
CHANGED
data/init.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Hammock
|
2
|
+
module LambdaComposition
|
3
|
+
MixInto = Proc
|
4
|
+
|
5
|
+
def self.included base # :nodoc:
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
base.send :extend, ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def self.compose f, g
|
13
|
+
L{|*args| f[g[*args]] }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
|
20
|
+
def * g
|
21
|
+
Proc.compose self, g
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Hammock
|
2
|
+
module Mutex
|
3
|
+
MixInto = ActiveRecord::Base
|
4
|
+
|
5
|
+
def self.included base # :nodoc:
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
base.send :extend, ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
module InstanceMethods
|
14
|
+
|
15
|
+
# Yield to the block after obtaining a column lock on +self+.
|
16
|
+
#
|
17
|
+
# The column lock is obtained by trying to set the given column to the
|
18
|
+
# current time. Since the check is done within UPDATE conditions and not
|
19
|
+
# a separate SELECT, it is atomic.
|
20
|
+
#
|
21
|
+
# After +block+ returns, the column is reset to NULL, at which point
|
22
|
+
# the lock can be obtained by other calls to +#mutex+. The NULL update is
|
23
|
+
# done within an +ensure+ block, so an exception within +block+ won't
|
24
|
+
# cause a stuck mutex.
|
25
|
+
#
|
26
|
+
# Example:
|
27
|
+
# @photo.mutex(:regenerating_thumbnails_at) { <some operation> }
|
28
|
+
def mutex column, &block
|
29
|
+
L{
|
30
|
+
sleep 1 and redo if self.class.update_all(
|
31
|
+
["#{connection.quote_column_name(column)} = ?", Time.now],
|
32
|
+
["#{connection.quote_column_name(self.class.primary_key)} = ? AND #{connection.quote_column_name(column)} IS NULL", id]
|
33
|
+
).zero?
|
34
|
+
yield
|
35
|
+
}.call
|
36
|
+
ensure
|
37
|
+
self.class.update_all(
|
38
|
+
["#{connection.quote_column_name(column)} = ?", nil],
|
39
|
+
["#{connection.quote_column_name(self.class.primary_key)} = ?", id]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/hammock.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Hoskings
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- README.rdoc
|
82
82
|
- Rakefile
|
83
83
|
- hammock.gemspec
|
84
|
+
- init.rb
|
84
85
|
- lib/hammock.rb
|
85
86
|
- lib/hammock/ajaxinate.rb
|
86
87
|
- lib/hammock/callback.rb
|
@@ -91,6 +92,8 @@ files:
|
|
91
92
|
- lib/hammock/export_scope.rb
|
92
93
|
- lib/hammock/hamlink_to.rb
|
93
94
|
- lib/hammock/javascript_buffer.rb
|
95
|
+
- lib/hammock/lambda_alias.rb
|
96
|
+
- lib/hammock/lambda_composition.rb
|
94
97
|
- lib/hammock/logging.rb
|
95
98
|
- lib/hammock/model_attributes.rb
|
96
99
|
- lib/hammock/model_logging.rb
|
@@ -104,6 +107,7 @@ files:
|
|
104
107
|
- lib/hammock/monkey_patches/object.rb
|
105
108
|
- lib/hammock/monkey_patches/route_set.rb
|
106
109
|
- lib/hammock/monkey_patches/string.rb
|
110
|
+
- lib/hammock/mutex.rb
|
107
111
|
- lib/hammock/overrides.rb
|
108
112
|
- lib/hammock/resource_mapping_hooks.rb
|
109
113
|
- lib/hammock/resource_retrieval.rb
|