autoload_resources 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/autoload_resources/able.rb +11 -5
- data/lib/autoload_resources/version.rb +1 -1
- data/spec/lib/autoload_resources/able_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e333dbcf25a499ea194e980a6d39e53bf2b2ef3f
|
4
|
+
data.tar.gz: d79573a5097d434f9583af3046e213cc10884947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0940f3a9c5dba0e015aece367191c7beb57189047c8573c3d6e9880f0c0111a7bb3c294c695b2a74821c9a2dcb44dedb85420574a14f950219d577966a56b40e
|
7
|
+
data.tar.gz: 73d9165426ef0201a05e9c40a2399f6c86243f2d921c0a21be284ee89425ba255e55804581adf8faecb28660a02bfa84b1f11bf5256d0273bdfaca7e160baae1
|
@@ -12,10 +12,6 @@ module AutoloadResources
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def autoload_base_class
|
16
|
-
self.class.autoload_base_class
|
17
|
-
end
|
18
|
-
|
19
15
|
module ClassMethods
|
20
16
|
|
21
17
|
def autoload_resources
|
@@ -54,11 +50,21 @@ module AutoloadResources
|
|
54
50
|
{
|
55
51
|
index: Proc.new { resource_class.all },
|
56
52
|
new: Proc.new { resource_class.new },
|
57
|
-
create:
|
53
|
+
create: default_create_proc,
|
58
54
|
[:show, :edit, :update, :destroy] => Proc.new { resource_class.find(params[:id]) }
|
59
55
|
}
|
60
56
|
end
|
61
57
|
|
58
|
+
def default_create_proc
|
59
|
+
Proc.new do
|
60
|
+
params_method = autoload_instance_variable_names(:create).find do |name|
|
61
|
+
self.respond_to? "#{name}_params"
|
62
|
+
end
|
63
|
+
return unless params_method
|
64
|
+
resource_class.new(send(params_method))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
62
68
|
def for_actions(actions, proc=nil, &block)
|
63
69
|
Array(actions).each do |action|
|
64
70
|
autoload_procs[action] = block || proc
|
@@ -63,12 +63,12 @@ describe ExamplesController do
|
|
63
63
|
expect(subject.instance_variable_get("@example")).to eq Example.new
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
it "should set the default for the
|
68
|
-
subject.autoload_resources(
|
66
|
+
[:show, :edit, :update, :destroy].each do |action_name|
|
67
|
+
it "should set the default for the #{action_name} action" do
|
68
|
+
subject.autoload_resources(action_name)
|
69
69
|
expect(subject.instance_variable_get("@example")).to eq Example.find
|
70
70
|
end
|
71
|
-
|
71
|
+
end
|
72
72
|
|
73
73
|
it "can set a custom block for an action" do
|
74
74
|
described_class.autoload_resources do
|