acts_as_controller_for 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,17 +50,22 @@ module ActsAsControllerFor
50
50
  end
51
51
  end
52
52
 
53
+ # <tt>block</tt> - the optional block defines the value of the models instance variable set for this action
53
54
  # GET /models/:id
54
55
  # GET /models/:id.xml
55
56
  # GET /models/:id.json
56
- def show
57
+ def show(&block)
57
58
  model = self.class.send :class_variable_get, :@@model
58
59
  options = self.class.send :class_variable_get, :@@options
59
60
 
60
61
  inst_var_ref = "@#{model.name.underscore}".to_sym
61
62
 
62
- if !options[:load_and_authorize]
63
- instance_variable_set inst_var_ref, model.find(params[:id])
63
+ if block
64
+ instance_variable_set inst_var_ref, yield
65
+ else
66
+ if !options[:load_and_authorize]
67
+ instance_variable_set inst_var_ref, model.find(params[:id])
68
+ end
64
69
  end
65
70
 
66
71
  respond_to do |format|
@@ -82,15 +87,20 @@ module ActsAsControllerFor
82
87
  end
83
88
  end
84
89
 
90
+ # <tt>block</tt> - the optional block defines the value of the models instance variable set for this action
85
91
  # GET /models/:id/edit
86
- def edit
92
+ def edit(&block)
87
93
  model = self.class.send :class_variable_get, :@@model
88
94
  options = self.class.send :class_variable_get, :@@options
89
95
 
90
96
  inst_var_ref = "@#{model.name.underscore}".to_sym
91
97
 
92
- if !options[:load_and_authorize]
93
- instance_variable_set inst_var_ref, model.find(params[:id])
98
+ if block
99
+ instance_variable_set inst_var_ref, yield
100
+ else
101
+ if !options[:load_and_authorize]
102
+ instance_variable_set inst_var_ref, model.find(params[:id])
103
+ end
94
104
  end
95
105
  end
96
106
 
@@ -2,7 +2,7 @@ module ActsAsControllerFor
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_controller_for
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jay Hayes
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-05 00:00:00 Z
13
+ date: 2011-08-11 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: This gem is an attempt to identify a pattern of simple rails controllers for common implementations