benhoskings-hammock 0.2.15.1 → 0.2.16

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.
@@ -1,3 +1,12 @@
1
+ == 0.2.16 2009-04-16
2
+ Use #nested_params_for in #make_new_record, instead of #params_for, to set nesting attributes like foreign keys.
3
+ Added #nested_params_for, to return the params for the current record plus all nestable 'blah_id' parameters.
4
+ Updated the implementation of current_hammock_resource to use #chomp! instead of regex matching and #gsub.
5
+ Fixed the find in find_record_on_create to query correctly with the current_nest_scope.
6
+ Use AR::Base.nestable_reflections in #determine_routing_parent instead of manual implementation.
7
+ Added AR::Base.nestable_reflections.
8
+
9
+
1
10
  == 0.2.15.1 2009-04-15
2
11
  Convert action_name to a symbol instead of a string before checking for ImpliedUnsafeActions.
3
12
  Revert "Switched from #in? to #include? for non-literal args, since it splats into a nested array and breaks."
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{hammock}
5
- s.version = "0.2.15.1"
5
+ s.version = "0.2.16"
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-15}
9
+ s.date = %q{2009-04-16}
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. 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!}
11
11
  s.email = ["ben@hoskings.net"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc", "misc/scaffold.txt"]
@@ -4,7 +4,7 @@ require 'ambition'
4
4
  require 'ambition/adapters/active_record'
5
5
 
6
6
  module Hammock
7
- VERSION = '0.2.15.1'
7
+ VERSION = '0.2.16'
8
8
 
9
9
  def self.included base # :nodoc:
10
10
  puts "Loading Hammock from #{loaded_from_gem? ? 'gem' : 'plugin'}"
@@ -21,6 +21,14 @@ module Hammock
21
21
  }
22
22
  end
23
23
 
24
+ def nestable_reflections
25
+ if nestable_routing_resources.nil?
26
+ reflections
27
+ else
28
+ reflections.dragnet *nestable_routing_resources
29
+ end
30
+ end
31
+
24
32
  def sorter
25
33
  # TODO updated_at DESC
26
34
  proc {|record| record.id }
@@ -136,7 +136,7 @@ module Hammock
136
136
 
137
137
  def find_record_on_create
138
138
  if findable_on_create?
139
- if record = current_nest_scope.find(:first, :conditions => params_for(mdl.symbolize))
139
+ if record = mdl.ambition_context.within(current_nest_scope).find(:first, :conditions => params_for(mdl.symbolize))
140
140
  log "suitable record already exists: #{record}"
141
141
  assign_entity record
142
142
  else
@@ -42,7 +42,7 @@ module Hammock
42
42
 
43
43
  # Returns the node in the Hammock routing map corresponding to the (possibly nested) resource handling the current request.
44
44
  def current_hammock_resource
45
- nesting_resources = params.keys.select {|k| /_id$/ =~ k }.map {|k| k.gsub(/_id$/, '').pluralize }
45
+ nesting_resources = params.keys.map {|k| k.dup.chomp!('_id') }.compact.map(&:pluralize)
46
46
  ActionController::Routing::Routes.route_map.base_for nesting_resources.push(mdl.resource_name).map(&:to_sym)
47
47
  end
48
48
 
@@ -64,6 +64,12 @@ module Hammock
64
64
  params[key] || {}
65
65
  end
66
66
 
67
+ def nested_params_for resource
68
+ params.
69
+ dragnet(*resource.nestable_reflections.keys.map {|i| "#{i.to_s}_id" }).
70
+ merge(params_for(resource.symbolize)).tap{|obj| log obj.inspect }
71
+ end
72
+
67
73
  def assign_entity record_or_records
68
74
  @entity = if record_or_records.nil?
69
75
  # Fail
@@ -98,7 +104,7 @@ module Hammock
98
104
  end
99
105
 
100
106
  def make_new_record resource = mdl
101
- resource.new_with(params_for(resource.symbolize))
107
+ resource.new_with nested_params_for resource
102
108
  end
103
109
 
104
110
  def assign_createable
@@ -124,7 +124,7 @@ module Hammock
124
124
  nil
125
125
  else
126
126
  # puts "reflections: #{resource.reflections.keys.inspect}"
127
- scannable_reflections = resource.nestable_routing_resources.nil? ? resource.reflections : resource.reflections.dragnet(*resource.nestable_routing_resources)
127
+ scannable_reflections = resource.nestable_reflections
128
128
  # puts "scannable reflections: #{scannable_reflections.keys.inspect}"
129
129
  valid_reflections = scannable_reflections.selekt {|k,v|
130
130
  # puts "#{v.klass}<#{v.object_id}> == #{parent.resource}<#{parent.resource.object_id}> #=> #{v.klass == parent.resource}"
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.15.1
4
+ version: 0.2.16
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-15 00:00:00 -07:00
12
+ date: 2009-04-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency