josevalim-inherited_resources 0.8.2 → 0.8.3

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.
Files changed (55) hide show
  1. data/Rakefile +16 -0
  2. data/VERSION +1 -0
  3. data/lib/inherited_resources.rb +8 -19
  4. data/lib/inherited_resources/actions.rb +3 -3
  5. data/lib/inherited_resources/base.rb +21 -11
  6. data/lib/inherited_resources/class_methods.rb +12 -20
  7. metadata +15 -63
  8. data/init.rb +0 -1
  9. data/lib/inherited_resources/spec.rb +0 -75
  10. data/test/locales/en.yml +0 -17
  11. data/test/views/cities/edit.html.erb +0 -1
  12. data/test/views/cities/index.html.erb +0 -1
  13. data/test/views/cities/new.html.erb +0 -1
  14. data/test/views/cities/show.html.erb +0 -1
  15. data/test/views/comments/edit.html.erb +0 -1
  16. data/test/views/comments/index.html.erb +0 -1
  17. data/test/views/comments/new.html.erb +0 -1
  18. data/test/views/comments/show.html.erb +0 -1
  19. data/test/views/employees/edit.html.erb +0 -1
  20. data/test/views/employees/index.html.erb +0 -1
  21. data/test/views/employees/new.html.erb +0 -1
  22. data/test/views/employees/show.html.erb +0 -1
  23. data/test/views/managers/edit.html.erb +0 -1
  24. data/test/views/managers/new.html.erb +0 -1
  25. data/test/views/managers/show.html.erb +0 -1
  26. data/test/views/painters/edit.html.erb +0 -1
  27. data/test/views/painters/index.html.erb +0 -1
  28. data/test/views/painters/new.html.erb +0 -1
  29. data/test/views/painters/show.html.erb +0 -1
  30. data/test/views/pets/edit.html.erb +0 -1
  31. data/test/views/pets/index.html.erb +0 -1
  32. data/test/views/pets/new.html.erb +0 -1
  33. data/test/views/pets/show.html.erb +0 -1
  34. data/test/views/products/edit.html.erb +0 -1
  35. data/test/views/products/index.html.erb +0 -1
  36. data/test/views/products/new.html.erb +0 -1
  37. data/test/views/products/show.html.erb +0 -1
  38. data/test/views/professors/edit.html.erb +0 -1
  39. data/test/views/professors/index.html.erb +0 -1
  40. data/test/views/professors/new.html.erb +0 -1
  41. data/test/views/professors/show.html.erb +0 -1
  42. data/test/views/projects/index.html.erb +0 -1
  43. data/test/views/projects/index.json.erb +0 -1
  44. data/test/views/projects/respond_to_skip_default_template.html.erb +0 -1
  45. data/test/views/projects/respond_to_with_resource.html.erb +0 -1
  46. data/test/views/students/edit.html.erb +0 -1
  47. data/test/views/students/new.html.erb +0 -1
  48. data/test/views/trees/edit.html.erb +0 -1
  49. data/test/views/trees/index.html.erb +0 -1
  50. data/test/views/trees/new.html.erb +0 -1
  51. data/test/views/trees/show.html.erb +0 -1
  52. data/test/views/users/edit.html.erb +0 -1
  53. data/test/views/users/index.html.erb +0 -1
  54. data/test/views/users/new.html.erb +0 -1
  55. data/test/views/users/show.html.erb +0 -1
data/Rakefile CHANGED
@@ -2,6 +2,22 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
 
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "inherited_resources"
9
+ s.rubyforge_project = "inherited_resources"
10
+ s.summary = "Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important."
11
+ s.email = "jose.valim@gmail.com"
12
+ s.homepage = "http://github.com/josevalim/inherited_resources"
13
+ s.description = "Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important."
14
+ s.authors = ['José Valim']
15
+ s.files = FileList["[A-Z]*", "{lib}/**/*"]
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
+ end
20
+
5
21
  desc 'Run tests for InheritedResources.'
6
22
  Rake::TestTask.new(:test) do |t|
7
23
  t.pattern = 'test/**/*_test.rb'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.8.3
@@ -6,24 +6,13 @@ require File.join(File.dirname(__FILE__), 'inherited_resources', 'respond_to')
6
6
  module InheritedResources; end
7
7
 
8
8
  class ActionController::Base
9
- class << self
10
- # If you cannot inherit from InheritedResources::Base you can call
11
- # inherit_resource or resource_controller in your controller to have all
12
- # the required modules and funcionality included.
13
- #
14
- def inherit_resources
15
- include InheritedResources::Actions
16
- include InheritedResources::BaseHelpers
17
- extend InheritedResources::ClassMethods
18
- extend InheritedResources::UrlHelpers
19
-
20
- helper_method :collection_url, :collection_path, :resource_url, :resource_path,
21
- :new_resource_url, :new_resource_path, :edit_resource_url, :edit_resource_path,
22
- :resource, :collection, :resource_class
23
-
24
- initialize_resources_class_accessors!
25
- create_resources_url_helpers!
26
- end
27
- alias :resource_controller :inherit_resources
9
+ # If you cannot inherit from InheritedResources::Base you can call
10
+ # inherit_resource in your controller to have all the required modules and
11
+ # funcionality included.
12
+ #
13
+ def self.inherit_resources
14
+ InheritedResources::Base.inherit_resources(self)
15
+ initialize_resources_class_accessors!
16
+ create_resources_url_helpers!
28
17
  end
29
18
  end
@@ -29,7 +29,7 @@ module InheritedResources
29
29
  alias :edit! :edit
30
30
 
31
31
  # POST /resources
32
- def create(redirect_url=nil, &block)
32
+ def create(&block)
33
33
  object = build_resource
34
34
  respond_block, redirect_block = select_block_by_arity(block)
35
35
 
@@ -52,7 +52,7 @@ module InheritedResources
52
52
  alias :create! :create
53
53
 
54
54
  # PUT /resources/1
55
- def update(redirect_url=nil, &block)
55
+ def update(&block)
56
56
  object = resource
57
57
  respond_block, redirect_block = select_block_by_arity(block)
58
58
 
@@ -76,7 +76,7 @@ module InheritedResources
76
76
  alias :update! :update
77
77
 
78
78
  # DELETE /resources/1
79
- def destroy(redirect_url=nil, &block)
79
+ def destroy(&block)
80
80
  resource.destroy
81
81
  respond_block, redirect_block = select_block_by_arity(block)
82
82
 
@@ -11,19 +11,29 @@ module InheritedResources
11
11
  class Base < ::ApplicationController
12
12
  unloadable
13
13
 
14
- include InheritedResources::Actions
15
- include InheritedResources::BaseHelpers
16
- extend InheritedResources::ClassMethods
17
- extend InheritedResources::UrlHelpers
14
+ # Overwrite inherit_resources to add specific InheritedResources behavior.
15
+ #
16
+ def self.inherit_resources(base)
17
+ base.class_eval do
18
+ include InheritedResources::Actions
19
+ include InheritedResources::BaseHelpers
20
+ extend InheritedResources::ClassMethods
21
+ extend InheritedResources::UrlHelpers
18
22
 
19
- helper_method :collection_url, :collection_path, :resource_url, :resource_path,
20
- :new_resource_url, :new_resource_path, :edit_resource_url, :edit_resource_path,
21
- :resource, :collection, :resource_class
23
+ helper_method :collection_url, :collection_path, :resource_url, :resource_path,
24
+ :new_resource_url, :new_resource_path, :edit_resource_url, :edit_resource_path,
25
+ :resource, :collection, :resource_class
22
26
 
23
- def self.inherited(base) #:nodoc:
24
- super(base)
25
- base.send :initialize_resources_class_accessors!
26
- base.send :create_resources_url_helpers!
27
+ base.with_options :instance_writer => false do |c|
28
+ c.class_inheritable_accessor :resource_class
29
+ c.class_inheritable_array :parents_symbols
30
+ c.class_inheritable_hash :resources_configuration, :scopes_configuration
31
+ end
32
+
33
+ protected :resource_class, :parents_symbols, :resources_configuration, :scopes_configuration
34
+ end
27
35
  end
36
+
37
+ inherit_resources(self)
28
38
  end
29
39
  end
@@ -1,7 +1,4 @@
1
1
  module InheritedResources
2
- RESOURCES_CLASS_ACCESSORS = [ :resource_class, :resources_configuration,
3
- :parents_symbols, :scopes_configuration ] unless self.const_defined?(:RESOURCES_CLASS_ACCESSORS)
4
-
5
2
  module ClassMethods
6
3
 
7
4
  protected
@@ -293,19 +290,6 @@ module InheritedResources
293
290
  # Initialize resources class accessors and set their default values.
294
291
  #
295
292
  def initialize_resources_class_accessors! #:nodoc:
296
- # Add and protect class accessors
297
- metaklass = (class << self; self; end)
298
-
299
- RESOURCES_CLASS_ACCESSORS.each do |cattr|
300
- cattr_accessor "#{cattr}", :instance_writer => false
301
-
302
- # Protect instance methods
303
- self.send :protected, cattr
304
-
305
- # Protect class writer
306
- metaklass.send :protected, "#{cattr}="
307
- end
308
-
309
293
  # Initialize resource class
310
294
  self.resource_class = begin
311
295
  self.controller_name.classify.constantize
@@ -314,7 +298,7 @@ module InheritedResources
314
298
  end
315
299
 
316
300
  # Initialize resources configuration hash
317
- self.resources_configuration = {}
301
+ self.resources_configuration ||= {}
318
302
  config = self.resources_configuration[:self] = {}
319
303
  config[:collection_name] = self.controller_name.to_sym
320
304
  config[:instance_name] = self.controller_name.singularize.to_sym
@@ -327,9 +311,17 @@ module InheritedResources
327
311
  config[:route_prefix] = namespaces.join('_') unless namespaces.empty?
328
312
 
329
313
  # Initialize polymorphic, singleton, scopes and belongs_to parameters
330
- self.parents_symbols = []
331
- self.scopes_configuration = {}
332
- self.resources_configuration[:polymorphic] = { :symbols => [], :optional => false }
314
+ self.parents_symbols ||= []
315
+ self.scopes_configuration ||= {}
316
+ self.resources_configuration[:polymorphic] ||= { :symbols => [], :optional => false }
317
+ end
318
+
319
+ # Hook called on inheritance.
320
+ #
321
+ def inherited(base) #:nodoc:
322
+ super(base)
323
+ base.send :initialize_resources_class_accessors!
324
+ base.send :create_resources_url_helpers!
333
325
  end
334
326
 
335
327
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: josevalim-inherited_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jos\xC3\xA9 Valim"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-28 00:00:00 -07:00
12
+ date: 2009-07-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,7 +26,7 @@ files:
26
26
  - MIT-LICENSE
27
27
  - README
28
28
  - Rakefile
29
- - init.rb
29
+ - VERSION
30
30
  - lib/inherited_resources.rb
31
31
  - lib/inherited_resources/actions.rb
32
32
  - lib/inherited_resources/base.rb
@@ -38,14 +38,12 @@ files:
38
38
  - lib/inherited_resources/polymorphic_helpers.rb
39
39
  - lib/inherited_resources/respond_to.rb
40
40
  - lib/inherited_resources/singleton_helpers.rb
41
- - lib/inherited_resources/spec.rb
42
41
  - lib/inherited_resources/url_helpers.rb
43
42
  has_rdoc: true
44
43
  homepage: http://github.com/josevalim/inherited_resources
45
44
  post_install_message:
46
45
  rdoc_options:
47
- - --main
48
- - README
46
+ - --charset=UTF-8
49
47
  require_paths:
50
48
  - lib
51
49
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -65,69 +63,23 @@ requirements: []
65
63
  rubyforge_project:
66
64
  rubygems_version: 1.2.0
67
65
  signing_key:
68
- specification_version: 2
66
+ specification_version: 3
69
67
  summary: Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.
70
68
  test_files:
71
- - test/aliases_test.rb
72
- - test/base_helpers_test.rb
69
+ - test/respond_to_test.rb
70
+ - test/customized_belongs_to_test.rb
71
+ - test/nested_belongs_to_test.rb
73
72
  - test/base_test.rb
74
- - test/belongs_to_test.rb
73
+ - test/redirect_to_test.rb
75
74
  - test/has_scope_test.rb
76
75
  - test/class_methods_test.rb
77
- - test/customized_belongs_to_test.rb
78
- - test/defaults_test.rb
76
+ - test/aliases_test.rb
79
77
  - test/flash_test.rb
80
- - test/nested_belongs_to_test.rb
81
- - test/optional_belongs_to_test.rb
78
+ - test/url_helpers_test.rb
79
+ - test/base_helpers_test.rb
80
+ - test/belongs_to_test.rb
82
81
  - test/polymorphic_test.rb
83
- - test/redirect_to_test.rb
84
- - test/respond_to_test.rb
82
+ - test/defaults_test.rb
85
83
  - test/singleton_test.rb
84
+ - test/optional_belongs_to_test.rb
86
85
  - test/test_helper.rb
87
- - test/url_helpers_test.rb
88
- - test/locales/en.yml
89
- - test/views/cities/edit.html.erb
90
- - test/views/cities/index.html.erb
91
- - test/views/cities/new.html.erb
92
- - test/views/cities/show.html.erb
93
- - test/views/comments/edit.html.erb
94
- - test/views/comments/index.html.erb
95
- - test/views/comments/new.html.erb
96
- - test/views/comments/show.html.erb
97
- - test/views/employees/edit.html.erb
98
- - test/views/employees/index.html.erb
99
- - test/views/employees/new.html.erb
100
- - test/views/employees/show.html.erb
101
- - test/views/managers/edit.html.erb
102
- - test/views/managers/new.html.erb
103
- - test/views/managers/show.html.erb
104
- - test/views/painters/edit.html.erb
105
- - test/views/painters/index.html.erb
106
- - test/views/painters/new.html.erb
107
- - test/views/painters/show.html.erb
108
- - test/views/pets/edit.html.erb
109
- - test/views/pets/index.html.erb
110
- - test/views/pets/new.html.erb
111
- - test/views/pets/show.html.erb
112
- - test/views/products/edit.html.erb
113
- - test/views/products/index.html.erb
114
- - test/views/products/new.html.erb
115
- - test/views/products/show.html.erb
116
- - test/views/professors/edit.html.erb
117
- - test/views/professors/index.html.erb
118
- - test/views/professors/new.html.erb
119
- - test/views/professors/show.html.erb
120
- - test/views/projects/index.html.erb
121
- - test/views/projects/index.json.erb
122
- - test/views/projects/respond_to_skip_default_template.html.erb
123
- - test/views/projects/respond_to_with_resource.html.erb
124
- - test/views/students/edit.html.erb
125
- - test/views/students/new.html.erb
126
- - test/views/trees/edit.html.erb
127
- - test/views/trees/index.html.erb
128
- - test/views/trees/new.html.erb
129
- - test/views/trees/show.html.erb
130
- - test/views/users/edit.html.erb
131
- - test/views/users/index.html.erb
132
- - test/views/users/new.html.erb
133
- - test/views/users/show.html.erb
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'inherited_resources')
@@ -1,75 +0,0 @@
1
- # This is a nasty rspec bug fix when using InheritedResources.
2
- # The bug exists on rspec <= 1.1.12 versions.
3
- #
4
- if defined?(Spec::Rails::Example::ControllerExampleGroup)
5
- unless Spec::Rails::Example::ControllerExampleGroup.const_defined?('TemplateIsolationExtensions')
6
-
7
- module Spec::Rails::Example
8
- class ControllerExampleGroup < FunctionalExampleGroup
9
- module ControllerInstanceMethods #:nodoc:
10
-
11
- # === render(options = nil, deprecated_status_or_extra_options = nil, &block)
12
- #
13
- # This gets added to the controller's singleton meta class,
14
- # allowing Controller Examples to run in two modes, freely switching
15
- # from context to context.
16
- def render(options=nil, deprecated_status_or_extra_options=nil, &block)
17
- if ::Rails::VERSION::STRING >= '2.0.0' && deprecated_status_or_extra_options.nil?
18
- deprecated_status_or_extra_options = {}
19
- end
20
-
21
- unless block_given?
22
- unless integrate_views?
23
- if @template.respond_to?(:finder)
24
- (class << @template.finder; self; end).class_eval do
25
- define_method :file_exists? do; true; end
26
- end
27
- else
28
- (class << @template; self; end).class_eval do
29
- define_method :file_exists? do; true; end
30
- end
31
- end
32
-
33
- (class << @template; self; end).send :include, TemplateIsolationExtensions
34
- end
35
- end
36
-
37
- if matching_message_expectation_exists(options)
38
- render_proxy.render(options, &block)
39
- @performed_render = true
40
- else
41
- if matching_stub_exists(options)
42
- @performed_render = true
43
- else
44
- super(options, deprecated_status_or_extra_options, &block)
45
- end
46
- end
47
- end
48
- end
49
-
50
- module TemplateIsolationExtensions
51
- def render_file(*args)
52
- @first_render ||= args[0] unless args[0] =~ /^layouts/
53
- @_first_render ||= args[0] unless args[0] =~ /^layouts/
54
- end
55
-
56
- def _pick_template(*args)
57
- @_first_render ||= args[0] unless args[0] =~ /^layouts/
58
- PickedTemplate.new
59
- end
60
-
61
- def render(*args)
62
- if @_rendered
63
- opts = args[0]
64
- (@_rendered[:template] ||= opts[:file]) if opts[:file]
65
- (@_rendered[:partials][opts[:partial]] += 1) if opts[:partial]
66
- else
67
- super
68
- end
69
- end
70
- end
71
- end
72
- end
73
-
74
- end
75
- end
data/test/locales/en.yml DELETED
@@ -1,17 +0,0 @@
1
- en:
2
- flash:
3
- addresses:
4
- create:
5
- notice: "You created a new address close to <b>{{reference}}</b>."
6
- update:
7
- notice: "Nice! {{resource_name}} was updated with success!"
8
- error: "Oh no! We could not update your address!"
9
- admin:
10
- actions:
11
- create:
12
- notice: "Admin notice message."
13
- error: "Admin error message."
14
- addresses:
15
- create:
16
- notice: "Admin, you created a new address close to <b>{{reference}}</b>."
17
-
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- Index JSON
@@ -1 +0,0 @@
1
- DefaultTemplate HTML
@@ -1 +0,0 @@
1
- RespondTo HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML
@@ -1 +0,0 @@
1
- Edit HTML
@@ -1 +0,0 @@
1
- Index HTML
@@ -1 +0,0 @@
1
- New HTML
@@ -1 +0,0 @@
1
- Show HTML