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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fd0f6f1956236b08235f03fe8eb30cc17ff99f6
4
- data.tar.gz: 21300054280c5831049fe2913fb093362c30c3e7
3
+ metadata.gz: e333dbcf25a499ea194e980a6d39e53bf2b2ef3f
4
+ data.tar.gz: d79573a5097d434f9583af3046e213cc10884947
5
5
  SHA512:
6
- metadata.gz: 80275e342a7e265f06165c3955dc1fc96e036b97c977edaaf20c842bed9e424f4d297f340f1cd7369308f531fca4230e61e950f91f143c0cd8b66fcac4757600
7
- data.tar.gz: d7fab591a556f147229c9cad61e661886f4241cdff339fc11a491ca40b7d9d8c8cdf00adf6f1abf4ba12d00313e930f480657202215d847a345565a90eedd751
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: Proc.new { resource_class.new(params[resource_class.model_name.element]) },
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
@@ -1,3 +1,3 @@
1
1
  module AutoloadResources
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
- # [:show, :edit, :update, :destroy].each do |action_name|
67
- it "should set the default for the :show action" do
68
- subject.autoload_resources(:show)
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
- # end
71
+ end
72
72
 
73
73
  it "can set a custom block for an action" do
74
74
  described_class.autoload_resources do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoload_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - barelyknown