josevalim-inherited_resources 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -38,7 +38,7 @@ Basic Usage
38
38
 
39
39
  To use Inherited Resources you just have to inherit (duh) it:
40
40
 
41
- class ProjectsController < ResourceController::Base
41
+ class ProjectsController < InheritedResources::Base
42
42
  end
43
43
 
44
44
  And all actions are defined and working, check it! Your projects collection
@@ -78,6 +78,15 @@ Or:
78
78
  actions :all, :except => [ :edit, :update, :destroy ]
79
79
  end
80
80
 
81
+ In your views, you will get the following helpers:
82
+
83
+ resource #=> @project
84
+ collection #=> @projects
85
+ resource_class #=> Project
86
+
87
+ As you might expect, collection (@projects instance variable) is only available
88
+ on index actions.
89
+
81
90
  Overwriting defaults
82
91
  --------------------
83
92
 
@@ -179,7 +188,8 @@ but you don't want to create a before filter for it:
179
188
  @project = Project.new(params[:project])
180
189
  @project.something_special!
181
190
  create!
182
- end end
191
+ end
192
+ end
183
193
 
184
194
  Yeap, that simple! The nice part is since you already set the instance variable
185
195
  @project, it will not do it again and overwrite your @project with something
@@ -298,7 +308,7 @@ When using polymorphic associations, you get some free helpers:
298
308
  parent? #=> true
299
309
  parent_type #=> :task
300
310
  parent_class #=> Task
301
- parent_instance #=> @task
311
+ parent #=> @task
302
312
 
303
313
  Polymorphic controller is another great idea by James Golick and he also uses
304
314
  that on resource_controller.
@@ -167,7 +167,8 @@ module InheritedResources
167
167
  extend InheritedResources::ClassMethods
168
168
 
169
169
  helper_method :collection_url, :collection_path, :resource_url, :resource_path,
170
- :new_resource_url, :new_resource_path, :edit_resource_url, :edit_resource_path
170
+ :new_resource_url, :new_resource_path, :edit_resource_url, :edit_resource_path,
171
+ :resource, :collection, :resource_class
171
172
 
172
173
  def self.inherited(base)
173
174
  base.class_eval do
@@ -123,7 +123,7 @@
123
123
  # parent? #=> true
124
124
  # parent_type #=> :task
125
125
  # parent_class #=> Task
126
- # parent_instance #=> @task
126
+ # parent #=> @task
127
127
  #
128
128
  # This polymorphic controllers thing is a great idea by James Golick and he
129
129
  # built it in resource_controller. Here is just a re-implementation.
@@ -113,6 +113,7 @@ module InheritedResources #:nodoc:
113
113
  def acts_as_polymorphic!
114
114
  if self.polymorphic_symbols.empty?
115
115
  include PolymorphicHelpers
116
+ helper_method :parent?, :parent_type, :parent_class, :parent
116
117
  end
117
118
  end
118
119
 
@@ -8,12 +8,13 @@ module InheritedResources #:nodoc:
8
8
  end
9
9
 
10
10
  def parent_class
11
- parent_instance.class
11
+ parent.class
12
12
  end
13
13
 
14
- def parent_instance
14
+ def parent
15
15
  instance_variable_get("@#{@parent_type}")
16
16
  end
17
+
17
18
  end
18
19
  end
19
20
 
@@ -52,7 +52,7 @@ module InheritedResources #:nodoc:
52
52
  base.parents_symbols.map do |symbol|
53
53
  if symbol == :polymorphic
54
54
  polymorphic = true
55
- resource_ivars << :parent_instance
55
+ resource_ivars << :parent
56
56
  else
57
57
  config = base.resources_configuration[symbol]
58
58
  resource_segments << config[:route_name]
@@ -90,7 +90,7 @@ module InheritedResources #:nodoc:
90
90
  end
91
91
 
92
92
  def self.generate_url_and_path_helpers(base, prefix, name, resource_segments, resource_ivars, polymorphic=false)
93
- ivars = resource_ivars.map{|i| i == :parent_instance ? :parent_instance : "@#{i}" }
93
+ ivars = resource_ivars.map{|i| i == :parent ? :parent : "@#{i}" }
94
94
 
95
95
  # If it's not a singleton, ivars are not empty, not a collection or
96
96
  # not a new hew helper, we can add args to the method.
@@ -277,6 +277,6 @@ class PolymorphicHelpersTest < TEST_CLASS
277
277
  assert_equal :factory, @controller.send(:parent_type)
278
278
  assert_equal Factory, @controller.send(:parent_class)
279
279
  assert_equal new_factory, assigns(:factory)
280
- assert_equal new_factory, @controller.send(:parent_instance)
280
+ assert_equal new_factory, @controller.send(:parent)
281
281
  end
282
282
  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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jos\xC3\xA9 Valim"