ddc 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/ddc/controller_builder.rb +30 -7
- data/lib/ddc/version.rb +1 -1
- data/spec/controller_builder_spec.rb +15 -0
- 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: 1e62db9575fb5178f54f19d956f70199f582275b
|
4
|
+
data.tar.gz: d37c726ec92c27889f8ffdb4654b2f023e143e9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94f69307b9649d32f6ba9742e5695f7a1812db92216e05f9d875d64f276d0971982d3dad31db7851eaeba337636ed5f7a4589078b9f7c6bbf0da349f159c8d21
|
7
|
+
data.tar.gz: 1d5e4053f091f76309479d695b8a61c37db675af9c9db3dfdbd19d34e967c664ffdbf566079b3772335eee83a9659638156b3b630555d1d76ca973d672009216
|
data/CHANGELOG.md
CHANGED
@@ -12,24 +12,47 @@ module DDC
|
|
12
12
|
}
|
13
13
|
class << self
|
14
14
|
def build(controller_name, config)
|
15
|
-
klass = find_or_create_class(controller_name)
|
15
|
+
klass = find_or_create_class(controller_name, config)
|
16
16
|
setup_before_actions!(klass, config)
|
17
17
|
setup_actions!(controller_name, klass, config)
|
18
18
|
klass
|
19
19
|
end
|
20
20
|
|
21
|
+
|
22
|
+
def specific_const_defined?(path)
|
23
|
+
path.split("::").inject(Object) do |mod, name|
|
24
|
+
return unless mod.const_defined?(name, false)
|
25
|
+
mod.const_get(name, false)
|
26
|
+
end
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
|
30
|
+
def specific_const_get(path)
|
31
|
+
path.split("::").inject(Object) do |mod, name|
|
32
|
+
mod.const_get(name, false)
|
33
|
+
end
|
34
|
+
end
|
21
35
|
|
22
|
-
def
|
36
|
+
def specific_const_set(path, klass)
|
37
|
+
path_pieces = path.split("::")
|
38
|
+
mod_name = path_pieces[0..-2].join("::")
|
39
|
+
mod = mod_name.present? ? Object.const_get(mod_name) : Object
|
40
|
+
mod.const_set(path_pieces.last, klass)
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_or_create_class(controller_name, config)
|
23
44
|
controller_klass_name = controller_name.to_s.camelize+'Controller'
|
24
45
|
klass = nil
|
25
|
-
if
|
26
|
-
klass =
|
46
|
+
if specific_const_defined?(controller_klass_name)
|
47
|
+
klass = specific_const_get(controller_klass_name)
|
27
48
|
else
|
28
|
-
|
29
|
-
|
49
|
+
parent_klass = config[:parent] || ApplicationController
|
50
|
+
klass = Class.new(parent_klass)
|
51
|
+
specific_const_set(controller_klass_name, klass)
|
30
52
|
end
|
53
|
+
klass
|
31
54
|
end
|
32
|
-
|
55
|
+
|
33
56
|
def setup_before_actions!(klass, config)
|
34
57
|
(config[:before_actions] || []).each do |ba|
|
35
58
|
klass.before_action ba
|
data/lib/ddc/version.rb
CHANGED
@@ -48,6 +48,21 @@ describe DDC::ControllerBuilder do
|
|
48
48
|
}}}).to raise_exception
|
49
49
|
end
|
50
50
|
|
51
|
+
it 'uses the provided parent class' do
|
52
|
+
class DarthVader
|
53
|
+
end
|
54
|
+
|
55
|
+
klass = subject.build :foo,
|
56
|
+
parent: DarthVader,
|
57
|
+
actions: {
|
58
|
+
index: {
|
59
|
+
context: 'foo_context_builder#bar',
|
60
|
+
service: 'baz_service#qux'
|
61
|
+
}
|
62
|
+
}
|
63
|
+
expect(klass.ancestors[1]).to be(DarthVader)
|
64
|
+
end
|
65
|
+
|
51
66
|
it 'adds the before actions' do
|
52
67
|
class FooController
|
53
68
|
def self.before_action(*args);end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|