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 +4 -4
- data/lib/autoload_resources/able.rb +17 -11
- data/lib/autoload_resources/version.rb +1 -1
- data/spec/lib/autoload_resources/able_spec.rb +13 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f43ba3d863dab5a06d3939fd682f712e70f447bb
|
4
|
+
data.tar.gz: 56926e89dd2ceaf3b9e6fcee1c19a99a75d0cc45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
7
|
-
|
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
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
@@ -20,21 +20,28 @@ class Example < ActiveRecord::Base
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
class
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|