cruddy 0.2.0 → 0.3.0
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f33dab1c1285bada28652e71f5d5169524e21b70
|
4
|
+
data.tar.gz: e449498a3b6706a28b4bd00e1263231b3d711da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c499eec7aba5bacd21094b1ba67e13b7cd0dfea6b3a152a3a2ba88aa703dc638404df8d0fb015ea34b15399654d5654f22198b509ffa1a3ad5c3c35b9d3db08
|
7
|
+
data.tar.gz: 6bfad2d1b000fc308f8157b95ac2b12d6330ef8f0cb99c4b523d2fade793ae54a41024bf48b5ed61a2e1ad96f3b2c6a4f42796f98441c720fe9168f03ad073ca
|
data/lib/cruddy/controller.rb
CHANGED
@@ -50,33 +50,67 @@ module Cruddy::Controller
|
|
50
50
|
params.require(resource_instance_name).permit!
|
51
51
|
end
|
52
52
|
|
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
|
58
|
+
|
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
|
64
|
+
|
53
65
|
# get the path to a singular resource
|
54
66
|
def resource_path(resource)
|
55
|
-
send("#{
|
67
|
+
send("#{resource_instance_path}", resource)
|
68
|
+
end
|
69
|
+
|
70
|
+
# get the path to edit a singular resource
|
71
|
+
def edit_resource_path(resource)
|
72
|
+
send("edit_#{resource_instance_path}", resource)
|
73
|
+
end
|
74
|
+
|
75
|
+
# get the path to create a new singular resource
|
76
|
+
def new_resource_path
|
77
|
+
send("new_#{resource_instance_path}")
|
56
78
|
end
|
57
79
|
|
58
80
|
# get the path to index resources
|
59
81
|
def resources_path
|
60
|
-
send("#{
|
82
|
+
send("#{resource_collection_path}")
|
83
|
+
end
|
84
|
+
|
85
|
+
# get the resource instance
|
86
|
+
def get_resource_instance
|
87
|
+
resource_class.find(params[:id])
|
88
|
+
end
|
89
|
+
|
90
|
+
# load the resource instance
|
91
|
+
def load_resource_instance
|
92
|
+
self.resource = get_resource_instance
|
61
93
|
end
|
62
94
|
|
63
|
-
|
64
|
-
|
95
|
+
# get the resource collection
|
96
|
+
def get_resource_collection
|
97
|
+
resource_class.all
|
65
98
|
end
|
66
99
|
|
67
|
-
|
68
|
-
|
100
|
+
# load the resource collection
|
101
|
+
def load_resource_collection
|
102
|
+
self.resources = get_resource_collection
|
69
103
|
end
|
70
104
|
|
71
105
|
# index action
|
72
106
|
def index
|
73
|
-
|
107
|
+
load_resource_collection
|
74
108
|
respond_with resources
|
75
109
|
end
|
76
110
|
|
77
111
|
# show action
|
78
112
|
def show
|
79
|
-
|
113
|
+
load_resource_instance
|
80
114
|
respond_with resource
|
81
115
|
end
|
82
116
|
|
@@ -101,13 +135,13 @@ module Cruddy::Controller
|
|
101
135
|
|
102
136
|
# edit action
|
103
137
|
def edit
|
104
|
-
|
138
|
+
load_resource_instance
|
105
139
|
respond_with resource
|
106
140
|
end
|
107
141
|
|
108
142
|
# update action
|
109
143
|
def update
|
110
|
-
|
144
|
+
load_resource_instance
|
111
145
|
|
112
146
|
if resource.update_attributes(resource_params)
|
113
147
|
redirect_to resource_path(resource)
|
@@ -120,7 +154,7 @@ module Cruddy::Controller
|
|
120
154
|
|
121
155
|
# destroy action
|
122
156
|
def destroy
|
123
|
-
|
157
|
+
load_resource_instance
|
124
158
|
resource.destroy
|
125
159
|
redirect_to resources_path
|
126
160
|
end
|
@@ -7,7 +7,6 @@ shared_examples "cruddy::controller#create" do
|
|
7
7
|
describe "POST create" do
|
8
8
|
context "when saved successfully" do
|
9
9
|
let(:instance) { mock_model resource_class, valid_resource_params.merge({save: true}) }
|
10
|
-
let(:instance_path_method) { "#{resource_instance_name}_path" }
|
11
10
|
let(:instance_path) { send(instance_path_method, instance) }
|
12
11
|
|
13
12
|
before do
|
@@ -27,7 +26,6 @@ shared_examples "cruddy::controller#create" do
|
|
27
26
|
|
28
27
|
context "when save fails" do
|
29
28
|
let(:instance) { mock_model resource_class, valid_resource_params.merge({save: false}) }
|
30
|
-
let(:instance_path_method) { "#{resource_instance_name}_path" }
|
31
29
|
|
32
30
|
before do
|
33
31
|
resource_class.stub(:new).with(valid_resource_params) { instance }
|
@@ -6,7 +6,6 @@ shared_examples "cruddy::controller#destroy" do
|
|
6
6
|
|
7
7
|
describe "DELETE destroy" do
|
8
8
|
let(:instance) { mock_model resource_class, destroy: true }
|
9
|
-
let(:collection_path_method) { "#{resource_collection_name}_path" }
|
10
9
|
let(:collection_path) { send(collection_path_method) }
|
11
10
|
|
12
11
|
before do
|
@@ -6,7 +6,6 @@ shared_examples "cruddy::controller#update" do
|
|
6
6
|
|
7
7
|
describe "PATCH update" do
|
8
8
|
let(:instance) { mock_model resource_class, update_attributes: true }
|
9
|
-
let(:instance_path_method) { "#{resource_instance_name}_path" }
|
10
9
|
let(:instance_path) { send(instance_path_method, instance) }
|
11
10
|
|
12
11
|
before do
|
data/lib/cruddy/version.rb
CHANGED