benhoskings-hammock 0.2.16 → 0.2.17

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 CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.17 2009-04-17
2
+ Refactored the logic from #update into #assign_and_save_record, and the #assign_attributes_for_save helper.
3
+
4
+
1
5
  == 0.2.16 2009-04-16
2
6
  Use #nested_params_for in #make_new_record, instead of #params_for, to set nesting attributes like foreign keys.
3
7
  Added #nested_params_for, to return the params for the current record plus all nestable 'blah_id' parameters.
data/hammock.gemspec CHANGED
@@ -2,12 +2,21 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{hammock}
5
- s.version = "0.2.16"
5
+ s.version = "0.2.17"
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-04-16}
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. Hammock enforces RESTful resource access by abstracting actions away from the controller in favour of a clean, model-like callback system. Hammock tackles the hard and soft sides of security at once with a scoping security system on your models. Specify who can verb what resources under what conditions once, and everything else - the actual security, link generation, index filtering - just happens. Hammock inspects your routes and resources to generate a routing tree for each resource. Parent resources in a nested route are handled transparently at every point - record retrieval, creation, and linking. It makes more sense when you see how it works though, so check out the screencast!}
9
+ s.date = %q{2009-04-17}
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
+
12
+
13
+ Hammock enforces RESTful resource access by abstracting actions away from the controller in favour of a clean, model-like callback system.
14
+
15
+ Hammock tackles the hard and soft sides of security at once with a scoping security system on your models. Specify who can verb what resources under what conditions once, and everything else - the actual security, link generation, index filtering - just happens.
16
+
17
+ Hammock inspects your routes and resources to generate a routing tree for each resource. Parent resources in a nested route are handled transparently at every point - record retrieval, creation, and linking.
18
+
19
+ It makes more sense when you see how it works though, so check out the screencast!}
11
20
  s.email = ["ben@hoskings.net"]
12
21
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc", "misc/scaffold.txt"]
13
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"]
@@ -16,12 +25,12 @@ Gem::Specification.new do |s|
16
25
  s.rdoc_options = ["--main", "README.rdoc"]
17
26
  s.require_paths = ["lib"]
18
27
  s.rubyforge_project = %q{hammock}
19
- s.rubygems_version = %q{1.3.1}
28
+ s.rubygems_version = %q{1.3.2}
20
29
  s.summary = %q{Hammock is a Rails plugin that eliminates redundant code in a very RESTful manner}
21
30
 
22
31
  if s.respond_to? :specification_version then
23
32
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 2
33
+ s.specification_version = 3
25
34
 
26
35
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
36
  s.add_runtime_dependency(%q<rails>, ["~> 2.2"])
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.2.16'
7
+ VERSION = '0.2.17'
8
8
 
9
9
  def self.included base # :nodoc:
10
10
  puts "Loading Hammock from #{loaded_from_gem? ? 'gem' : 'plugin'}"
@@ -65,14 +65,7 @@ module Hammock
65
65
  # Updates the specified record with the supplied attributes if it is within the current write scope, defined by +write_scope+ and +write_scope_for+ on the current model.
66
66
  def update
67
67
  if find_record
68
- # If params[:attribute] is given, update only that attribute. We mass-assign either way to filter through attr_accessible.
69
- @record.attributes = if (attribute_name = params[:attribute])
70
- { attribute_name => params_for(mdl.symbolize)[attribute_name] }
71
- else
72
- params_for mdl.symbolize
73
- end
74
-
75
- render_or_redirect_after save_record
68
+ render_or_redirect_after assign_and_save_record
76
69
  end
77
70
  end
78
71
 
@@ -124,6 +117,13 @@ module Hammock
124
117
  end
125
118
 
126
119
 
120
+ protected
121
+
122
+ def assign_and_save_record
123
+ save_record if assign_attributes_for_save
124
+ end
125
+
126
+
127
127
  private
128
128
 
129
129
  def tasks_for_index
@@ -145,6 +145,15 @@ module Hammock
145
145
  end
146
146
  end
147
147
 
148
+ def assign_attributes_for_save
149
+ # If params[:attribute] is given, update only that attribute. We mass-assign either way to filter through attr_accessible.
150
+ @record.attributes = if (attribute_name = params[:attribute])
151
+ { attribute_name => params_for(mdl.symbolize)[attribute_name] }
152
+ else
153
+ params_for mdl.symbolize
154
+ end
155
+ end
156
+
148
157
  def save_record
149
158
  verb = @record.new_record? ? 'create' : 'update'
150
159
  if callback("before_#{verb}") and callback(:before_save) and save
@@ -67,7 +67,7 @@ module Hammock
67
67
  def nested_params_for resource
68
68
  params.
69
69
  dragnet(*resource.nestable_reflections.keys.map {|i| "#{i.to_s}_id" }).
70
- merge(params_for(resource.symbolize)).tap{|obj| log obj.inspect }
70
+ merge(params_for(resource.symbolize))
71
71
  end
72
72
 
73
73
  def assign_entity record_or_records
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.2.16
4
+ version: 0.2.17
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-04-16 00:00:00 -07:00
12
+ date: 2009-04-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -136,7 +136,7 @@ requirements: []
136
136
  rubyforge_project: hammock
137
137
  rubygems_version: 1.2.0
138
138
  signing_key:
139
- specification_version: 2
139
+ specification_version: 3
140
140
  summary: Hammock is a Rails plugin that eliminates redundant code in a very RESTful manner
141
141
  test_files: []
142
142