benhoskings-hammock 0.2.11.4 → 0.2.12
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 +10 -0
- data/Rakefile +6 -6
- data/hammock.gemspec +2 -2
- data/lib/hammock.rb +13 -8
- data/lib/hammock/resource_retrieval.rb +11 -13
- data/lib/hammock/restful_actions.rb +1 -10
- data/lib/hammock/route_node.rb +11 -7
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.2.12 2009-03-31
|
2
|
+
Added loading message.
|
3
|
+
Moved require for hammock components within Hammock.included.
|
4
|
+
Commented debugging output in #determine_routing_parent.
|
5
|
+
Removed InstanceMethods and ClassMethods internal modules from RestfulActions, to explicitly include it more cleanly in ApplicationController.
|
6
|
+
Fix the loading code to achieve the same load whether hammock is installed as a plugin or a gem.
|
7
|
+
Send toplevel loading include to ActionController::Base instead of reopening ApplicationController.
|
8
|
+
Replaced escort_for_40[34] with render_for_status, which chooses the first available from controller partial, shared partial, static page and uses the correct HTTP status code.
|
9
|
+
|
10
|
+
|
1
11
|
== 0.2.11.4 2009-03-25
|
2
12
|
Don't encodeURIComponent() the authenticity_token, as it's not required and breaks non-alphanumeric chars.
|
3
13
|
|
data/Rakefile
CHANGED
@@ -6,13 +6,13 @@ require File.dirname(__FILE__) + '/lib/hammock'
|
|
6
6
|
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
7
7
|
$hoe = Hoe.new('hammock', Hammock::VERSION) do |p|
|
8
8
|
p.developer('Ben Hoskings', 'ben@hoskings.net')
|
9
|
-
p.changes
|
10
|
-
p.rubyforge_name
|
11
|
-
p.extra_deps
|
12
|
-
['rails','~> 2.2'],
|
13
|
-
['benhoskings-ambitious-activerecord','~> 0.1.3.5'],
|
9
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
10
|
+
p.rubyforge_name = p.name
|
11
|
+
p.extra_deps = [
|
12
|
+
['rails', '~> 2.2'],
|
13
|
+
['benhoskings-ambitious-activerecord', '~> 0.1.3.5'],
|
14
14
|
]
|
15
|
-
p.extra_dev_deps
|
15
|
+
p.extra_dev_deps = [
|
16
16
|
['newgem', ">= #{::Newgem::VERSION}"]
|
17
17
|
]
|
18
18
|
|
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.2.
|
5
|
+
s.version = "0.2.12"
|
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-03-
|
9
|
+
s.date = %q{2009-03-31}
|
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"]
|
data/lib/hammock.rb
CHANGED
@@ -3,14 +3,16 @@ gem 'benhoskings-ambitious-activerecord'
|
|
3
3
|
require 'ambition'
|
4
4
|
require 'ambition/adapters/active_record'
|
5
5
|
|
6
|
-
Dir.glob("#{File.dirname __FILE__}/hammock/**/*.rb").each {|dep|
|
7
|
-
require dep
|
8
|
-
} if defined?(RAILS_ROOT) # Loading Hammock components under 'rake package' fails.
|
9
|
-
|
10
6
|
module Hammock
|
11
|
-
VERSION = '0.2.
|
7
|
+
VERSION = '0.2.12'
|
12
8
|
|
13
9
|
def self.included base # :nodoc:
|
10
|
+
puts "Loading Hammock from #{loaded_from_gem? ? 'gem' : 'plugin'}"
|
11
|
+
|
12
|
+
Dir.glob("#{File.dirname __FILE__}/hammock/**/*.rb").each {|dep|
|
13
|
+
require dep
|
14
|
+
}
|
15
|
+
|
14
16
|
Hammock.constants.map {|constant_name|
|
15
17
|
Hammock.const_get constant_name
|
16
18
|
}.select {|constant|
|
@@ -22,8 +24,11 @@ module Hammock
|
|
22
24
|
target.send :include, mod
|
23
25
|
}
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def self.loaded_from_gem?
|
29
|
+
File.dirname(__FILE__)[`gem env gemdir`.chomp]
|
30
|
+
end
|
29
31
|
end
|
32
|
+
|
33
|
+
# This is done in init.rb when Hammock is loaded as a plugin.
|
34
|
+
ActionController::Base.send :include, Hammock if Hammock.loaded_from_gem?
|
@@ -69,11 +69,12 @@ module Hammock
|
|
69
69
|
elsif :readonly == reason
|
70
70
|
escort_for_read_only
|
71
71
|
elsif :unauthed == reason
|
72
|
-
|
72
|
+
# TODO Write a 403 partial.
|
73
|
+
render_for_status 404
|
73
74
|
elsif current_user.nil? && account_verb_scope?
|
74
75
|
escort_for_login
|
75
76
|
else
|
76
|
-
|
77
|
+
render_for_status 404
|
77
78
|
end
|
78
79
|
false
|
79
80
|
end
|
@@ -99,18 +100,15 @@ module Hammock
|
|
99
100
|
# render :partial => 'login/account', :status => 401 # unauthorized
|
100
101
|
redirect_to returning_login_path
|
101
102
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
render :
|
107
|
-
|
108
|
-
|
109
|
-
def escort_for_403
|
110
|
-
if partial_exists? 'shared/status_404'
|
111
|
-
render :partial => 'shared/status_404', :layout => true
|
103
|
+
|
104
|
+
def render_for_status code
|
105
|
+
log code
|
106
|
+
if partial_exists? "#{controller_name}/status_#{code}"
|
107
|
+
render :partial => "#{controller_name}/status_#{code}", :layout => true, :status => code
|
108
|
+
elsif partial_exists? "shared/status_#{code}"
|
109
|
+
render :partial => "shared/status_#{code}", :layout => true, :status => code
|
112
110
|
else
|
113
|
-
render :file => File.join(RAILS_ROOT,
|
111
|
+
render :file => File.join(RAILS_ROOT, "public/#{code}.html"), :status => code
|
114
112
|
end
|
115
113
|
end
|
116
114
|
|
@@ -1,14 +1,6 @@
|
|
1
1
|
module Hammock
|
2
2
|
module RestfulActions
|
3
|
-
|
4
|
-
base.send :include, InstanceMethods
|
5
|
-
base.send :extend, ClassMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
end
|
10
|
-
|
11
|
-
module InstanceMethods
|
3
|
+
MixInto = ApplicationController
|
12
4
|
|
13
5
|
# The +index+ action. (GET, safe, idempotent)
|
14
6
|
#
|
@@ -167,6 +159,5 @@ module Hammock
|
|
167
159
|
@record.save
|
168
160
|
end
|
169
161
|
|
170
|
-
end
|
171
162
|
end
|
172
163
|
end
|
data/lib/hammock/route_node.rb
CHANGED
@@ -118,22 +118,26 @@ module Hammock
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def determine_routing_parent
|
121
|
-
puts "\ndetermine_routing_parent: #{mdl}:"
|
121
|
+
# puts "\ndetermine_routing_parent: #{mdl}:"
|
122
122
|
if parent.nil? || parent.resource.nil?
|
123
|
-
puts "Resource for #{mdl} has either no parent or no resource - not nestable."
|
123
|
+
# puts "Resource for #{mdl} has either no parent or no resource - not nestable."
|
124
124
|
nil
|
125
125
|
else
|
126
|
-
puts "reflections: #{resource.reflections.keys.inspect}"
|
127
|
-
puts "nestable_routing_resources: #{resource.nestable_routing_resources.inspect}"
|
126
|
+
# puts "reflections: #{resource.reflections.keys.inspect}"
|
128
127
|
scannable_reflections = resource.nestable_routing_resources.nil? ? resource.reflections : resource.reflections.dragnet(*resource.nestable_routing_resources)
|
129
|
-
puts "scannable reflections: #{scannable_reflections.keys.inspect}"
|
130
|
-
valid_reflections = scannable_reflections.selekt {|k,v|
|
131
|
-
|
128
|
+
# puts "scannable reflections: #{scannable_reflections.keys.inspect}"
|
129
|
+
valid_reflections = scannable_reflections.selekt {|k,v|
|
130
|
+
# puts "#{v.klass}<#{v.object_id}> == #{parent.resource}<#{parent.resource.object_id}> #=> #{v.klass == parent.resource}"
|
131
|
+
v.klass == parent.resource
|
132
|
+
}
|
133
|
+
# puts "valid reflections: #{valid_reflections.keys.inspect}"
|
132
134
|
|
133
135
|
if valid_reflections.keys.length < 1
|
134
136
|
raise "The routing table specifies that #{mdl} is nested within #{parent.mdl}, but there is no ActiveRecord association linking #{resource} to #{parent.resource}. Example: 'belongs_to :#{parent.resource.base_model}' in the #{resource} model."
|
135
137
|
elsif valid_reflections.keys.length > 1
|
136
138
|
raise "#{resource} defines more than one association to #{parent.resource} (#{valid_reflections.keys.map(&:to_s).join(', ')}). That's fine, but you need to use #{resource}.nest_within to specify the one Hammock should nest scopes through. For example, 'nest_within #{valid_reflections.keys.first.inspect}' in the #{resource} model."
|
139
|
+
# else
|
140
|
+
# puts "Routing #{mdl} within #{valid_reflections.keys.first} (chose from #{scannable_reflections.inspect})"
|
137
141
|
end
|
138
142
|
|
139
143
|
valid_reflections.keys.first
|
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.
|
4
|
+
version: 0.2.12
|
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-03-
|
12
|
+
date: 2009-03-31 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|