hammock 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.5.7 2010-02-21
2
+ Flatten resource lists instead of splatting, to avoid implicit #to_a on Ambition contexts.
3
+ Don't eval JS responses in the XHR callback, since it already happens automatically.
4
+
5
+
1
6
  == 0.5.6 2010-01-07
2
7
  Fixed Hammock.loaded_from_gem? to work for any gem path, not just `gem env gemdir`.
3
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.6
1
+ 0.5.7
data/hammock.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hammock}
8
- s.version = "0.5.6"
8
+ s.version = "0.5.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Hoskings"]
12
- s.date = %q{2010-01-07}
12
+ s.date = %q{2010-02-21}
13
13
  s.description = %q{}
14
14
  s.email = %q{ben@hoskings.net}
15
15
  s.extra_rdoc_files = [
@@ -104,7 +104,7 @@ module Hammock
104
104
  private
105
105
 
106
106
  def link_class_for verb, entities, attribute = nil
107
- [*entities].map(&:description).
107
+ [entities].flatten.map(&:description).
108
108
  unshift(verb).push(attribute).
109
109
  compact.join('_')
110
110
  end
@@ -70,7 +70,7 @@ module Hammock
70
70
  subclasses.each &:reset_cached_column_info
71
71
  end
72
72
 
73
- def find_or_new_with(find_attributes, create_attributes = {})
73
+ def find_or_new_with(find_attributes, create_attributes = {}, should_assign = false)
74
74
  finder = respond_to?(:find_with_destroyed) ? :find_with_destroyed : :find
75
75
 
76
76
  if record = send(finder, :first, :conditions => find_attributes.discard(:deleted_at))
@@ -80,6 +80,7 @@ module Hammock
80
80
  # (c) it is deleted, but we want to find one that's deleted, or
81
81
  # (d) we don't want a deleted record, and undestruction succeeds.
82
82
  if (finder != :find_with_destroyed) || !record.deleted? || create_attributes[:deleted_at] || record.restore
83
+ record.attributes = create_attributes if should_assign
83
84
  record
84
85
  end
85
86
  else
@@ -28,7 +28,12 @@ module Hammock
28
28
  yield self
29
29
  self
30
30
  end
31
-
31
+
32
+ def tapp
33
+ log self.inspect
34
+ self
35
+ end
36
+
32
37
  # The reverse of <tt>Enumerable#include?</tt> - returns +true+ if +self+ is
33
38
  # equal to one of the elements of +args+.
34
39
  def in? first, *rest
@@ -89,7 +89,7 @@ module Hammock
89
89
 
90
90
  def returning_login_path
91
91
  session[:path_after_login] = request.request_uri
92
- login_path
92
+ signin_path
93
93
  end
94
94
 
95
95
  def escort_for_bad_request
@@ -73,18 +73,16 @@ module Hammock
73
73
  merge(params_for(resource.symbolize))
74
74
  end
75
75
 
76
- def assign_entity record_or_records
77
- @entity = if record_or_records.nil?
78
- # Fail
79
- elsif record_or_records.is_a? ActiveRecord::Base
80
- instance_variable_set "@#{mdl_name}", (@record = record_or_records)
81
- elsif record_or_records.is_a? Ambition::Context
82
- # log "Unkicked query: #{record_or_records.to_hash.inspect}"
83
- instance_variable_set "@#{mdl_name.pluralize}", (@records = record_or_records)
84
- elsif record_or_records.is_a? Array
85
- instance_variable_set "@#{mdl_name.pluralize}", (@records = record_or_records)
86
- else
87
- raise "Unknown record(s) type #{record_or_records.class}."
76
+ def assign_entity entity
77
+ @entity = if entity.is_a? ActiveRecord::Base
78
+ instance_variable_set "@#{mdl_name}", (@record = entity)
79
+ elsif entity.is_a? Ambition::Context
80
+ # log "Unkicked query: #{entity.to_hash.inspect}"
81
+ instance_variable_set "@#{mdl_name.pluralize}", (@records = entity)
82
+ elsif entity.is_a? Array
83
+ instance_variable_set "@#{mdl_name.pluralize}", (@records = entity)
84
+ elsif !entity.nil?
85
+ raise "Unknown record(s) type #{entity.class}."
88
86
  end
89
87
 
90
88
  @entity if assign_nesting_entities
data/lib/hammock/scope.rb CHANGED
@@ -45,11 +45,11 @@ module Hammock
45
45
  route = route_for verb, *entities
46
46
  if route.verb.in?(:save, :create) && record.new_record?
47
47
  returning record.createable_by?(current_user) ? :ok : :unauthed do |result|
48
- dlog "#{requester_name} can#{"'t" unless result == :ok} create a #{record.class} with #{record.attributes.inspect}. #{describe_call_point 4}"
48
+ # dlog "#{requester_name} can#{"'t" unless result == :ok} create a #{record.class} with #{record.attributes.inspect}. #{describe_call_point 4}"
49
49
  end
50
50
  else
51
51
  returning record_in_scope?(route, record) ? :ok : :not_found do |result|
52
- dlog "#{requester_name} can#{"'t" unless result == :ok} #{verb} #{record.class}<#{record.id}>. #{describe_call_point 4}"
52
+ # dlog "#{requester_name} can#{"'t" unless result == :ok} #{verb} #{record.class}<#{record.id}>. #{describe_call_point 4}"
53
53
  end
54
54
  end
55
55
  end
@@ -52,7 +52,7 @@ var fire_hammock_ajax = function(data) {
52
52
  ),
53
53
  function(response, textStatus) {
54
54
  if (data.format == 'js') {
55
- eval(response);
55
+ // JS responses are evaluated automatically
56
56
  } else {
57
57
  jQuery('.' + (data.target || data.klass + '_target')).before(response).remove();
58
58
  }
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.5.6
4
+ version: 0.5.7
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: 2010-01-07 00:00:00 +10:00
12
+ date: 2010-02-21 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency