cruddy 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f33dab1c1285bada28652e71f5d5169524e21b70
4
- data.tar.gz: e449498a3b6706a28b4bd00e1263231b3d711da9
3
+ metadata.gz: 9cd6d5c002cf3bc7bb2f69dc6ac50a98b6baaf62
4
+ data.tar.gz: cad487e1435cbf4dfefb655c9cff0f61fc012406
5
5
  SHA512:
6
- metadata.gz: 8c499eec7aba5bacd21094b1ba67e13b7cd0dfea6b3a152a3a2ba88aa703dc638404df8d0fb015ea34b15399654d5654f22198b509ffa1a3ad5c3c35b9d3db08
7
- data.tar.gz: 6bfad2d1b000fc308f8157b95ac2b12d6330ef8f0cb99c4b523d2fade793ae54a41024bf48b5ed61a2e1ad96f3b2c6a4f42796f98441c720fe9168f03ad073ca
6
+ metadata.gz: 16109537493706747f10f68d2d4efc93537c063017a87ef492eff8f37291fe728ceaafa0e475a65516f7c9f6c9398bba529cea5e7047fdf0bab30414cb63962f
7
+ data.tar.gz: ce88c9a91aa78877c81feb4ac31d0fb8cbaeb629abb98b367465582cf1a0fff6133c5952b2b581bb2728894d8f13b2ca5c7c393c594d6299ee8797dec0d7a27c
@@ -1,167 +1,169 @@
1
- module Cruddy::Controller
2
- module ClassMethods
3
- # choose which actions the controller inherits
4
- def actions(*methods)
5
- methods_to_remove = [:index, :show, :new, :create, :edit, :update, :destroy].reject { |m| methods.include?(m) }
6
- methods_to_remove.each do |method_to_remove|
7
- undef_method method_to_remove
1
+ module Cruddy
2
+ module Controller
3
+ module ClassMethods
4
+ # choose which actions the controller inherits
5
+ def actions(*methods)
6
+ methods_to_remove = [:index, :show, :new, :create, :edit, :update, :destroy].reject { |m| methods.include?(m) }
7
+ methods_to_remove.each do |method_to_remove|
8
+ undef_method method_to_remove
9
+ end
8
10
  end
9
11
  end
10
- end
11
12
 
12
- module InstanceMethods
13
- # the class this controller manages
14
- def resource_class
15
- controller_name.classify.constantize
16
- end
13
+ module InstanceMethods
14
+ # the class this controller manages
15
+ def resource_class
16
+ controller_name.classify.constantize
17
+ end
17
18
 
18
- # the name of the resource collection
19
- def resource_collection_name
20
- controller_name
21
- end
19
+ # the name of the resource collection
20
+ def resource_collection_name
21
+ controller_name
22
+ end
22
23
 
23
- # the name of the singular resource
24
- def resource_instance_name
25
- controller_name.singularize
26
- end
24
+ # the name of the singular resource
25
+ def resource_instance_name
26
+ controller_name.singularize
27
+ end
27
28
 
28
- # get instance variable for singluar resource instance
29
- def resource
30
- instance_variable_get("@#{resource_instance_name}")
31
- end
29
+ # get instance variable for singluar resource instance
30
+ def resource
31
+ instance_variable_get("@#{resource_instance_name}")
32
+ end
32
33
 
33
- # set instance variable for singluar resource instance
34
- def resource=(resource)
35
- instance_variable_set("@#{resource_instance_name}", resource)
36
- end
34
+ # set instance variable for singluar resource instance
35
+ def resource=(resource)
36
+ instance_variable_set("@#{resource_instance_name}", resource)
37
+ end
37
38
 
38
- # get instance variable for collection of resource instances
39
- def resources
40
- instance_variable_get("@#{resource_collection_name}")
41
- end
39
+ # get instance variable for collection of resource instances
40
+ def resources
41
+ instance_variable_get("@#{resource_collection_name}")
42
+ end
42
43
 
43
- # set instance variable for collection of resource instances
44
- def resources=(collection)
45
- instance_variable_set("@#{resource_collection_name}", collection)
46
- end
44
+ # set instance variable for collection of resource instances
45
+ def resources=(collection)
46
+ instance_variable_set("@#{resource_collection_name}", collection)
47
+ end
47
48
 
48
- # require the resource and permit all params by default
49
- def resource_params
50
- params.require(resource_instance_name).permit!
51
- end
49
+ # require the resource and permit all params by default
50
+ def resource_params
51
+ params.require(resource_instance_name).permit!
52
+ end
52
53
 
53
- # get the path to the collection of resources, including the namespace
54
- def resource_collection_path
55
- path_start = controller_path.gsub('/', '_')
56
- "#{path_start}_path"
57
- end
54
+ # get the path to the collection of resources, including the namespace
55
+ def resource_collection_path
56
+ path_start = controller_path.gsub('/', '_')
57
+ "#{path_start}_path"
58
+ end
58
59
 
59
- # get the path to a singular resource, including the namespace
60
- def resource_instance_path
61
- path_start = controller_path.gsub('/', '_').singularize
62
- "#{path_start}_path"
63
- end
60
+ # get the path to a singular resource, including the namespace
61
+ def resource_instance_path
62
+ path_start = controller_path.gsub('/', '_').singularize
63
+ "#{path_start}_path"
64
+ end
64
65
 
65
- # get the path to a singular resource
66
- def resource_path(resource)
67
- send("#{resource_instance_path}", resource)
68
- end
66
+ # get the path to a singular resource
67
+ def resource_path(resource)
68
+ send("#{resource_instance_path}", resource)
69
+ end
69
70
 
70
- # get the path to edit a singular resource
71
- def edit_resource_path(resource)
72
- send("edit_#{resource_instance_path}", resource)
73
- end
71
+ # get the path to edit a singular resource
72
+ def edit_resource_path(resource)
73
+ send("edit_#{resource_instance_path}", resource)
74
+ end
74
75
 
75
- # get the path to create a new singular resource
76
- def new_resource_path
77
- send("new_#{resource_instance_path}")
78
- end
76
+ # get the path to create a new singular resource
77
+ def new_resource_path
78
+ send("new_#{resource_instance_path}")
79
+ end
79
80
 
80
- # get the path to index resources
81
- def resources_path
82
- send("#{resource_collection_path}")
83
- end
81
+ # get the path to index resources
82
+ def resources_path
83
+ send("#{resource_collection_path}")
84
+ end
84
85
 
85
- # get the resource instance
86
- def get_resource_instance
87
- resource_class.find(params[:id])
88
- end
86
+ # get the resource instance
87
+ def get_resource_instance
88
+ resource_class.find(params[:id])
89
+ end
89
90
 
90
- # load the resource instance
91
- def load_resource_instance
92
- self.resource = get_resource_instance
93
- end
91
+ # load the resource instance
92
+ def load_resource_instance
93
+ self.resource = get_resource_instance
94
+ end
94
95
 
95
- # get the resource collection
96
- def get_resource_collection
97
- resource_class.all
98
- end
96
+ # get the resource collection
97
+ def get_resource_collection
98
+ resource_class.all
99
+ end
99
100
 
100
- # load the resource collection
101
- def load_resource_collection
102
- self.resources = get_resource_collection
103
- end
101
+ # load the resource collection
102
+ def load_resource_collection
103
+ self.resources = get_resource_collection
104
+ end
104
105
 
105
- # index action
106
- def index
107
- load_resource_collection
108
- respond_with resources
109
- end
106
+ # index action
107
+ def index
108
+ load_resource_collection
109
+ respond_with resources
110
+ end
110
111
 
111
- # show action
112
- def show
113
- load_resource_instance
114
- respond_with resource
115
- end
112
+ # show action
113
+ def show
114
+ load_resource_instance
115
+ respond_with resource
116
+ end
116
117
 
117
- # new action
118
- def new
119
- self.resource = resource_class.new
120
- respond_with resource
121
- end
118
+ # new action
119
+ def new
120
+ self.resource = resource_class.new
121
+ respond_with resource
122
+ end
122
123
 
123
- # create action
124
- def create
125
- self.resource = resource_class.new(resource_params)
124
+ # create action
125
+ def create
126
+ self.resource = resource_class.new(resource_params)
126
127
 
127
- if resource.save
128
- redirect_to resource_path(resource)
129
- else
130
- respond_with(resource) do |format|
131
- format.html { render :new }
128
+ if resource.save
129
+ redirect_to resource_path(resource)
130
+ else
131
+ respond_with(resource) do |format|
132
+ format.html { render :new }
133
+ end
132
134
  end
133
135
  end
134
- end
135
136
 
136
- # edit action
137
- def edit
138
- load_resource_instance
139
- respond_with resource
140
- end
137
+ # edit action
138
+ def edit
139
+ load_resource_instance
140
+ respond_with resource
141
+ end
141
142
 
142
- # update action
143
- def update
144
- load_resource_instance
143
+ # update action
144
+ def update
145
+ load_resource_instance
145
146
 
146
- if resource.update_attributes(resource_params)
147
- redirect_to resource_path(resource)
148
- else
149
- respond_with(resource) do |format|
150
- format.html { render :edit }
147
+ if resource.update_attributes(resource_params)
148
+ redirect_to resource_path(resource)
149
+ else
150
+ respond_with(resource) do |format|
151
+ format.html { render :edit }
152
+ end
151
153
  end
152
154
  end
153
- end
154
155
 
155
- # destroy action
156
- def destroy
157
- load_resource_instance
158
- resource.destroy
159
- redirect_to resources_path
156
+ # destroy action
157
+ def destroy
158
+ load_resource_instance
159
+ resource.destroy
160
+ redirect_to resources_path
161
+ end
160
162
  end
161
- end
162
163
 
163
- def self.included(receiver)
164
- receiver.extend ClassMethods
165
- receiver.send :include, InstanceMethods
164
+ def self.included(receiver)
165
+ receiver.extend ClassMethods
166
+ receiver.send :include, InstanceMethods
167
+ end
166
168
  end
167
169
  end
@@ -1,3 +1,3 @@
1
1
  module Cruddy
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cruddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rehberg