hammock 0.2.11.4 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
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/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.11.4"
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-25}
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"]
@@ -69,11 +69,12 @@ module Hammock
69
69
  elsif :readonly == reason
70
70
  escort_for_read_only
71
71
  elsif :unauthed == reason
72
- escort_for_403
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
- escort_for_404
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
- def escort_for_404
103
- if partial_exists? 'shared/status_404'
104
- render :partial => 'shared/status_404', :layout => true
105
- else
106
- render :file => File.join(RAILS_ROOT, 'public/404.html'), :status => 404
107
- end
108
- end
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, 'public/404.html'), :status => 403
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
- def self.included base # :nodoc:
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
@@ -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| puts "#{v.klass}<#{v.object_id}> == #{parent.resource}<#{parent.resource.object_id}> #=> #{v.klass == parent.resource}"; v.klass == parent.resource }
131
- puts "valid reflections: #{valid_reflections.keys.inspect}"
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
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.11.4'
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
- class ApplicationController < ActionController::Base
28
- include Hammock
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?
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.2.11.4
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-25 00:00:00 +10:00
12
+ date: 2009-03-31 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency