autoload_resources 0.0.5 → 0.0.6

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: 21bed64325a6b9eefc9df6a89f1cfb3ecf3e5a9b
4
- data.tar.gz: ed47fd0f9880ea564a155d962c54bd27092dfe5d
3
+ metadata.gz: f43ba3d863dab5a06d3939fd682f712e70f447bb
4
+ data.tar.gz: 56926e89dd2ceaf3b9e6fcee1c19a99a75d0cc45
5
5
  SHA512:
6
- metadata.gz: 21a72f3ad372a6284846fbefcde80c7be36f47f49462ea470904b8c8650b59b6577bfce8568c1f3c1600bbcb1482fe82b59686b52b09c6fbde8edd00d9a0ec19
7
- data.tar.gz: 7275b7292be0eb6cb4420b9be42301be1b868def9ecd88583b396174304a8729e96abae72af1b4531ea6f21c7ba1e5efa3aadf7454709434e1094afc6ba0ddc0
6
+ metadata.gz: 7f69eb8bcf422a2398eb7c3e2fc8f936b2743005f74d0efaef254f80d835a9d20da14259c5c30faf0d282ef581e6e46d574a08d03164a006bd4d52358f400752
7
+ data.tar.gz: 76565ecafb8160d7958ad1e9e7438c8b898ff3348e4f431f8430bb80a53159c95f4af33ccf15493a6b23eff4c658abab09ce2d6b8197ef52807efe26eb175794
@@ -3,14 +3,20 @@ module AutoloadResources
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def autoload_resources(action_name=params[:action])
6
- return unless self.class.autoload_procs[action_name]
7
- value = instance_eval(&(self.class.autoload_procs[action_name]))
6
+ proc = self.class.ancestors.grep(Class).select do |klass|
7
+ klass.ancestors.include?(ActionController::Base) && klass != ActionController::Base
8
+ end.collect do |klass|
9
+ klass.autoload_procs[action_name]
10
+ end.compact.first
11
+ return unless proc
12
+ value = instance_eval(&proc)
8
13
  self.class.autoload_instance_variable_names(action_name).each do |instance_variable_name|
9
14
  instance_variable_set(
10
15
  "@#{instance_variable_name}",
11
16
  value
12
17
  )
13
18
  end
19
+ value
14
20
  end
15
21
 
16
22
  module ClassMethods
@@ -58,7 +64,8 @@ module AutoloadResources
58
64
 
59
65
  def default_create_proc
60
66
  Proc.new do
61
- create_params_method and resource_class.new(send(create_params_method))
67
+ params_method = self.class.create_params_method
68
+ params_method and resource_class.new(send(params_method))
62
69
  end
63
70
  end
64
71
 
@@ -69,15 +76,14 @@ module AutoloadResources
69
76
  end
70
77
  alias_method :for_action, :for_actions
71
78
 
72
- end
73
-
74
- private
75
- def create_params_method
76
- self.class.autoload_instance_variable_names(:create).collect do |element|
77
- element + "_params"
78
- end.find do |params_method_name|
79
- self.respond_to? params_method_name
79
+ def create_params_method
80
+ autoload_instance_variable_names(:create).collect do |element|
81
+ element + "_params"
82
+ end.find do |params_method_name|
83
+ private_method_defined? params_method_name
84
+ end
80
85
  end
86
+
81
87
  end
82
88
 
83
89
  end
@@ -1,3 +1,3 @@
1
1
  module AutoloadResources
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -20,21 +20,28 @@ class Example < ActiveRecord::Base
20
20
  end
21
21
  end
22
22
 
23
- class ExamplesController
23
+ class ActionController
24
+ class Base
25
+ def self.helper_method(method_name); end
26
+ def self.before_action(method); end
27
+ end
28
+ end
29
+
30
+ class ExamplesController < ActionController::Base
24
31
  include ControllerResourceClass::Able
25
32
  include AutoloadResources::Able
26
33
 
27
- def self.before_action(method)
28
- end
29
34
 
30
- def self.controller_name
31
- "examples"
32
- end
35
+ # def self.controller_name
36
+ # "examples"
37
+ # end
33
38
 
34
39
  def params
35
40
  { id: 3 }
36
41
  end
37
42
 
43
+
44
+
38
45
  end
39
46
 
40
47
  describe ExamplesController do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoload_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - barelyknown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2013-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler