benhoskings-hammock 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.3.9 2009-06-18
2
+ Improved logging in find_record_on_create.
3
+ Enabled :indicate_current support in #hamlink_to, using RouteStep#matches?.
4
+ Added RouteStep#matches?, to check if the receiving RouteStep represents the given request.
5
+
6
+
1
7
  == 0.3.8 2009-06-05
2
8
  Added LambdaAlias dep to RouteDrawingHooks, for Hammock.load_models.
3
9
  Added LambdaComposition component.
data/hammock.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{hammock}
5
- s.version = "0.3.8"
5
+ s.version = "0.3.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Hoskings"]
9
- s.date = %q{2009-06-05}
9
+ s.date = %q{2009-06-18}
10
10
  s.description = %q{Hammock is a Rails plugin that eliminates redundant code in a very RESTful manner. It does this in lots in lots of different places, but in one manner: it encourages specification in place of implementation.
11
11
 
12
12
 
@@ -19,7 +19,7 @@ Hammock inspects your routes and resources to generate a routing tree for each r
19
19
  It makes more sense when you see how it works though. There's a screencast coming soon.}
20
20
  s.email = ["ben@hoskings.net"]
21
21
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc", "misc/scaffold.txt"]
22
- s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "hammock.gemspec", "lib/hammock.rb", "lib/hammock/ajaxinate.rb", "lib/hammock/callback.rb", "lib/hammock/callbacks.rb", "lib/hammock/canned_scopes.rb", "lib/hammock/constants.rb", "lib/hammock/controller_attributes.rb", "lib/hammock/export_scope.rb", "lib/hammock/hamlink_to.rb", "lib/hammock/javascript_buffer.rb", "lib/hammock/logging.rb", "lib/hammock/model_attributes.rb", "lib/hammock/model_logging.rb", "lib/hammock/monkey_patches/action_pack.rb", "lib/hammock/monkey_patches/active_record.rb", "lib/hammock/monkey_patches/array.rb", "lib/hammock/monkey_patches/hash.rb", "lib/hammock/monkey_patches/logger.rb", "lib/hammock/monkey_patches/module.rb", "lib/hammock/monkey_patches/numeric.rb", "lib/hammock/monkey_patches/object.rb", "lib/hammock/monkey_patches/route_set.rb", "lib/hammock/monkey_patches/string.rb", "lib/hammock/overrides.rb", "lib/hammock/resource_mapping_hooks.rb", "lib/hammock/resource_retrieval.rb", "lib/hammock/restful_actions.rb", "lib/hammock/restful_rendering.rb", "lib/hammock/restful_support.rb", "lib/hammock/route_drawing_hooks.rb", "lib/hammock/route_for.rb", "lib/hammock/route_node.rb", "lib/hammock/route_step.rb", "lib/hammock/scope.rb", "lib/hammock/suggest.rb", "lib/hammock/utils.rb", "misc/scaffold.txt", "misc/template.rb", "tasks/hammock_tasks.rake", "test/hammock_test.rb"]
22
+ s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "hammock.gemspec", "init.rb", "lib/hammock.rb", "lib/hammock/ajaxinate.rb", "lib/hammock/callback.rb", "lib/hammock/callbacks.rb", "lib/hammock/canned_scopes.rb", "lib/hammock/constants.rb", "lib/hammock/controller_attributes.rb", "lib/hammock/export_scope.rb", "lib/hammock/hamlink_to.rb", "lib/hammock/javascript_buffer.rb", "lib/hammock/lambda_alias.rb", "lib/hammock/lambda_composition.rb", "lib/hammock/logging.rb", "lib/hammock/model_attributes.rb", "lib/hammock/model_logging.rb", "lib/hammock/monkey_patches/action_pack.rb", "lib/hammock/monkey_patches/active_record.rb", "lib/hammock/monkey_patches/array.rb", "lib/hammock/monkey_patches/hash.rb", "lib/hammock/monkey_patches/logger.rb", "lib/hammock/monkey_patches/module.rb", "lib/hammock/monkey_patches/numeric.rb", "lib/hammock/monkey_patches/object.rb", "lib/hammock/monkey_patches/route_set.rb", "lib/hammock/monkey_patches/string.rb", "lib/hammock/mutex.rb", "lib/hammock/overrides.rb", "lib/hammock/resource_mapping_hooks.rb", "lib/hammock/resource_retrieval.rb", "lib/hammock/restful_actions.rb", "lib/hammock/restful_rendering.rb", "lib/hammock/restful_support.rb", "lib/hammock/route_drawing_hooks.rb", "lib/hammock/route_for.rb", "lib/hammock/route_node.rb", "lib/hammock/route_step.rb", "lib/hammock/scope.rb", "lib/hammock/suggest.rb", "lib/hammock/utils.rb", "misc/scaffold.txt", "misc/template.rb", "tasks/hammock_tasks.rake", "test/hammock_test.rb"]
23
23
  s.homepage = %q{http://github.com/benhoskings/hammock}
24
24
  s.rdoc_options = ["--main", "README.rdoc"]
25
25
  s.require_paths = ["lib"]
@@ -34,18 +34,18 @@ It makes more sense when you see how it works though. There's a screencast comin
34
34
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
35
35
  s.add_runtime_dependency(%q<rails>, ["~> 2.2"])
36
36
  s.add_runtime_dependency(%q<benhoskings-ambitious-activerecord>, ["~> 0.1.3.7"])
37
- s.add_development_dependency(%q<newgem>, [">= 1.3.0"])
37
+ s.add_development_dependency(%q<newgem>, [">= 1.4.1"])
38
38
  s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
39
39
  else
40
40
  s.add_dependency(%q<rails>, ["~> 2.2"])
41
41
  s.add_dependency(%q<benhoskings-ambitious-activerecord>, ["~> 0.1.3.7"])
42
- s.add_dependency(%q<newgem>, [">= 1.3.0"])
42
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
43
43
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
44
44
  end
45
45
  else
46
46
  s.add_dependency(%q<rails>, ["~> 2.2"])
47
47
  s.add_dependency(%q<benhoskings-ambitious-activerecord>, ["~> 0.1.3.7"])
48
- s.add_dependency(%q<newgem>, [">= 1.3.0"])
48
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
49
49
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
50
50
  end
51
51
  end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # This loads hammock when it's present as a plugin.
2
+ # As a gem, it's loaded from lib/hammock.rb.
3
+ Hammock::IncludeTarget.send :include, Hammock
data/lib/hammock.rb CHANGED
@@ -4,7 +4,7 @@ require 'ambition'
4
4
  require 'ambition/adapters/active_record'
5
5
 
6
6
  module Hammock
7
- VERSION = '0.3.8'
7
+ VERSION = '0.3.9'
8
8
  IncludeTarget = ActionController::Base
9
9
 
10
10
  def self.included base # :nodoc:
@@ -24,7 +24,7 @@ module Hammock
24
24
  if can_verb_entity?(verb, entity)
25
25
  route = route_for *args.push(opts.dragnet(:nest, :format))
26
26
 
27
- # opts[:class] = ['current', opts[:class]].squash.join(' ') if opts[:indicate_current] && (route == controller.current_route)
27
+ opts[:class] = ['current', opts[:class]].squash.join(' ') if opts[:indicate_current] && route.matches?(request)
28
28
  opts[:class] = [link_class_for(route.verb, entity), opts[:class]].squash.join(' ')
29
29
 
30
30
  text = opts.delete(:text) || opts.delete(:text_or_else)
@@ -0,0 +1,12 @@
1
+ module Hammock
2
+ module LambdaAlias
3
+ MixInto = Kernel
4
+
5
+ def self.included base # :nodoc:
6
+ base.class_eval {
7
+ alias :L :lambda
8
+ }
9
+ end
10
+
11
+ end
12
+ end
@@ -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
@@ -130,10 +130,10 @@ module Hammock
130
130
  def find_record_on_create
131
131
  if findable_on_create?
132
132
  if record = mdl.ambition_context.within(current_nest_scope).find(:first, :conditions => params_for(mdl.symbolize))
133
- log "suitable record already exists: #{record}"
133
+ log "Suitable #{record.class}<#{record.id}> already exists."
134
134
  assign_entity record
135
135
  else
136
- log "couldn't find a suitable record, proceeding with creation."
136
+ log "Couldn't find a suitable #{mdl}, proceeding with creation."
137
137
  end
138
138
  end
139
139
  end
@@ -31,6 +31,11 @@ module Hammock
31
31
  !@entity.nil?
32
32
  end
33
33
 
34
+ def matches? request
35
+ (path == request.path) &&
36
+ (http_method == request.method)
37
+ end
38
+
34
39
  def path params = nil
35
40
  raise_unless_setup_while_trying_to 'render a path'
36
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benhoskings-hammock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hoskings
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-05 00:00:00 -07:00
12
+ date: 2009-06-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.3.0
43
+ version: 1.4.1
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: hoe
@@ -71,6 +71,7 @@ files:
71
71
  - README.rdoc
72
72
  - Rakefile
73
73
  - hammock.gemspec
74
+ - init.rb
74
75
  - lib/hammock.rb
75
76
  - lib/hammock/ajaxinate.rb
76
77
  - lib/hammock/callback.rb
@@ -81,6 +82,8 @@ files:
81
82
  - lib/hammock/export_scope.rb
82
83
  - lib/hammock/hamlink_to.rb
83
84
  - lib/hammock/javascript_buffer.rb
85
+ - lib/hammock/lambda_alias.rb
86
+ - lib/hammock/lambda_composition.rb
84
87
  - lib/hammock/logging.rb
85
88
  - lib/hammock/model_attributes.rb
86
89
  - lib/hammock/model_logging.rb
@@ -94,6 +97,7 @@ files:
94
97
  - lib/hammock/monkey_patches/object.rb
95
98
  - lib/hammock/monkey_patches/route_set.rb
96
99
  - lib/hammock/monkey_patches/string.rb
100
+ - lib/hammock/mutex.rb
97
101
  - lib/hammock/overrides.rb
98
102
  - lib/hammock/resource_mapping_hooks.rb
99
103
  - lib/hammock/resource_retrieval.rb