benhoskings-hammock 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,8 +1,13 @@
1
+ == 0.2.11 2009-03-23
2
+ Added hammock include hook to hammock.rb, to sidestep changed ApplicationController load behaviour in Rails 2.3.
3
+ Added pagination support to the index route.
4
+ Changed #mdl and #mdl_name implementations to class methods, and re-aliased them as instance methods.
5
+
1
6
  == 0.2.10 2009-03-17
2
7
  Added AR::Base.suggest_scope for narrowing the scope in the suggest action.
3
8
  Changed identifier in AR::Base#concise_inspect from #id to #to_param.
4
9
  Fixed raise condition for entities arg to RouteNode#for, and improved exception message.
5
- Changed squash! to compact! in route_for, to only remove nil elements (and not, say, models with no records that respond true to bla
10
+ Changed squash! to compact! in route_for, to only remove nil elements (and not, say, models with no records that respond true to blank?).
6
11
 
7
12
 
8
13
  == 0.2.9 2009-03-13
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ %w[action_controller].each { |f| require f }
2
3
  require File.dirname(__FILE__) + '/lib/hammock'
3
4
 
4
5
  # Generate all the Rake tasks
@@ -8,7 +9,8 @@ $hoe = Hoe.new('hammock', Hammock::VERSION) do |p|
8
9
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
10
  p.rubyforge_name = p.name
10
11
  p.extra_deps = [
11
- ['benhoskings-ambitious-activerecord','>= 0.1.3.4'],
12
+ ['rails','~> 2.2.2'],
13
+ ['benhoskings-ambitious-activerecord','~> 0.1.3.5'],
12
14
  ]
13
15
  p.extra_dev_deps = [
14
16
  ['newgem', ">= #{::Newgem::VERSION}"]
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.10"
5
+ s.version = "0.2.11"
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-17}
9
+ s.date = %q{2009-03-23}
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"]
@@ -24,17 +24,20 @@ Gem::Specification.new do |s|
24
24
  s.specification_version = 2
25
25
 
26
26
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
- s.add_runtime_dependency(%q<benhoskings-ambitious-activerecord>, [">= 0.1.3.4"])
28
- s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
27
+ s.add_runtime_dependency(%q<railslol>, ["~> 2.2.2"])
28
+ s.add_runtime_dependency(%q<benhoskings-ambitious-activerecord>, ["~> 0.1.3.5"])
29
+ s.add_development_dependency(%q<newgem>, [">= 1.3.0"])
29
30
  s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
30
31
  else
31
- s.add_dependency(%q<benhoskings-ambitious-activerecord>, [">= 0.1.3.4"])
32
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
32
+ s.add_dependency(%q<railslol>, ["~> 2.2.2"])
33
+ s.add_dependency(%q<benhoskings-ambitious-activerecord>, ["~> 0.1.3.5"])
34
+ s.add_dependency(%q<newgem>, [">= 1.3.0"])
33
35
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
34
36
  end
35
37
  else
36
- s.add_dependency(%q<benhoskings-ambitious-activerecord>, [">= 0.1.3.4"])
37
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
38
+ s.add_dependency(%q<railslol>, ["~> 2.2.2"])
39
+ s.add_dependency(%q<benhoskings-ambitious-activerecord>, ["~> 0.1.3.5"])
40
+ s.add_dependency(%q<newgem>, [">= 1.3.0"])
38
41
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
39
42
  end
40
43
  end
data/lib/hammock.rb CHANGED
@@ -8,7 +8,7 @@ Dir.glob("#{File.dirname __FILE__}/hammock/**/*.rb").each {|dep|
8
8
  } if defined?(RAILS_ROOT) # Loading Hammock components under 'rake package' fails.
9
9
 
10
10
  module Hammock
11
- VERSION = '0.2.10'
11
+ VERSION = '0.2.11'
12
12
 
13
13
  def self.included base # :nodoc:
14
14
  Hammock.constants.map {|constant_name|
@@ -23,3 +23,7 @@ module Hammock
23
23
  }
24
24
  end
25
25
  end
26
+
27
+ class ApplicationController < ActionController::Base
28
+ include Hammock
29
+ end
@@ -21,6 +21,15 @@ module Hammock
21
21
  def find_on_create
22
22
  write_inheritable_attribute :find_on_create, true
23
23
  end
24
+
25
+ def paginate_by per_page
26
+ write_inheritable_attribute :pagination_enabled, true
27
+ mdl.metaclass.instance_eval do
28
+ define_method :per_page do
29
+ per_page
30
+ end
31
+ end
32
+ end
24
33
  end
25
34
 
26
35
  module InstanceMethods
@@ -34,6 +43,10 @@ module Hammock
34
43
  def findable_on_create?
35
44
  self.class.read_inheritable_attribute :find_on_create
36
45
  end
46
+
47
+ def pagination_enabled?
48
+ self.class.read_inheritable_attribute :pagination_enabled
49
+ end
37
50
  end
38
51
  end
39
52
  end
@@ -40,7 +40,11 @@ module Hammock
40
40
  if (scope = current_scope).nil?
41
41
  escort :unauthed
42
42
  else
43
- assign_entity scope
43
+ if pagination_enabled?
44
+ assign_entity scope.paginate(:page => params[:page])
45
+ else
46
+ assign_entity scope
47
+ end
44
48
  end
45
49
  end
46
50
 
@@ -17,6 +17,15 @@ module Hammock
17
17
 
18
18
  module ClassMethods
19
19
 
20
+ # The model this controller operates on. Defined as the singularized controller name. For example, for +GelatinousBlobsController+, this will return the +GelatinousBlob+ class.
21
+ def mdl
22
+ @hammock_cached_mdl ||= Object.const_get to_s.sub('Controller', '').classify
23
+ end
24
+ # The lowercase name of the model this controller operates on. For example, for +GelatinousBlobsController+, this will return "gelatinous_blob".
25
+ def mdl_name
26
+ @hammock_cached_mdl_name ||= to_s.sub('Controller', '').singularize.underscore
27
+ end
28
+
20
29
  end
21
30
 
22
31
  module InstanceMethods
@@ -24,11 +33,11 @@ module Hammock
24
33
 
25
34
  # The model this controller operates on. Defined as the singularized controller name. For example, for +GelatinousBlobsController+, this will return the +GelatinousBlob+ class.
26
35
  def mdl
27
- @hammock_cached_mdl ||= Object.const_get self.class.to_s.sub('Controller', '').classify
36
+ self.class.mdl
28
37
  end
29
38
  # The lowercase name of the model this controller operates on. For example, for +GelatinousBlobsController+, this will return "gelatinous_blob".
30
39
  def mdl_name
31
- @hammock_cached_mdl_name ||= self.class.to_s.sub('Controller', '').singularize.underscore
40
+ self.class.mdl_name
32
41
  end
33
42
 
34
43
  # Returns the node in the Hammock routing map corresponding to the (possibly nested) resource handling the current request.
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.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hoskings
@@ -9,18 +9,28 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-17 00:00:00 -07:00
12
+ date: 2009-03-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: railslol
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.2.2
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: benhoskings-ambitious-activerecord
17
27
  type: :runtime
18
28
  version_requirement:
19
29
  version_requirements: !ruby/object:Gem::Requirement
20
30
  requirements:
21
- - - ">="
31
+ - - ~>
22
32
  - !ruby/object:Gem::Version
23
- version: 0.1.3.4
33
+ version: 0.1.3.5
24
34
  version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: newgem
@@ -30,7 +40,7 @@ dependencies:
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
33
- version: 1.2.3
43
+ version: 1.3.0
34
44
  version:
35
45
  - !ruby/object:Gem::Dependency
36
46
  name: hoe