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: cd5f65ae0d8e5fbc42faedeec4c6bac4c5fe4a5b
4
- data.tar.gz: b6e370ecf958708e99f742950773082538cb85de
3
+ metadata.gz: f33dab1c1285bada28652e71f5d5169524e21b70
4
+ data.tar.gz: e449498a3b6706a28b4bd00e1263231b3d711da9
5
5
  SHA512:
6
- metadata.gz: c18e696df5e4acde6af2aaa74e30d1cefc1c2f28c034c9f39126d5c7bf0cda82784b57e061439c8bb8177c853e7eff0796df7954cf8e5193251dfaa630902394
7
- data.tar.gz: c83da586307d94f24b91c2bd4db7979ebfdedea2742e6e595703382e97e0dae4d7ccae31e3986be2d51e348823d9e64bd572680cdfa2f019d41f1fca9de4db7a
6
+ metadata.gz: 8c499eec7aba5bacd21094b1ba67e13b7cd0dfea6b3a152a3a2ba88aa703dc638404df8d0fb015ea34b15399654d5654f22198b509ffa1a3ad5c3c35b9d3db08
7
+ data.tar.gz: 6bfad2d1b000fc308f8157b95ac2b12d6330ef8f0cb99c4b523d2fade793ae54a41024bf48b5ed61a2e1ad96f3b2c6a4f42796f98441c720fe9168f03ad073ca
@@ -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("#{resource_instance_name}_path", resource)
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("#{resource_collection_name}_path")
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
- def find_resource_instance
64
- self.resource = resource_class.find(params[:id])
95
+ # get the resource collection
96
+ def get_resource_collection
97
+ resource_class.all
65
98
  end
66
99
 
67
- def find_resource_collection
68
- self.resources = resource_class.all
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
- find_resource_collection
107
+ load_resource_collection
74
108
  respond_with resources
75
109
  end
76
110
 
77
111
  # show action
78
112
  def show
79
- find_resource_instance
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
- find_resource_instance
138
+ load_resource_instance
105
139
  respond_with resource
106
140
  end
107
141
 
108
142
  # update action
109
143
  def update
110
- find_resource_instance
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
- find_resource_instance
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
@@ -1,3 +1,3 @@
1
1
  module Cruddy
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rehberg