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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 730dff323e8780de877e38da76e5f9095eb14664
4
- data.tar.gz: bcebe8c41b6acaad90efb3454b7145dcf629c135
3
+ metadata.gz: 1e62db9575fb5178f54f19d956f70199f582275b
4
+ data.tar.gz: d37c726ec92c27889f8ffdb4654b2f023e143e9b
5
5
  SHA512:
6
- metadata.gz: d5e577bfaf5d03c1c7684b0b2b98178a0f384ace150a2ff0e9f011ac727a4eb09bce2574fdcb866e60d4f4d3ea258371517f5d8c36e80c2a18e4f3daac2d8570
7
- data.tar.gz: 2ab75c7a10cca1ef97d0af014a0b01ab6234ddcd548c94e564cc1486a0ace6ee103f39f10c081d3d4d419562f76991dfef5c5d4e6216b54cf16edc3389f6d76a
6
+ metadata.gz: 94f69307b9649d32f6ba9742e5695f7a1812db92216e05f9d875d64f276d0971982d3dad31db7851eaeba337636ed5f7a4589078b9f7c6bbf0da349f159c8d21
7
+ data.tar.gz: 1d5e4053f091f76309479d695b8a61c37db675af9c9db3dfdbd19d34e967c664ffdbf566079b3772335eee83a9659638156b3b630555d1d76ca973d672009216
@@ -1,5 +1,14 @@
1
1
  # DDC Changelog
2
2
 
3
+ ### 0.1.7
4
+
5
+ * patch to fix 0.1.6 bug
6
+
7
+ ### 0.1.6
8
+
9
+ * remove use of `qualified_const_*` calls to fix a bug with global lookup
10
+ * add :parent option
11
+
3
12
  ### 0.1.5
4
13
 
5
14
  * remove :render_opts to use :object_render_opts
@@ -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 find_or_create_class(controller_name)
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 Object.qualified_const_defined?(controller_klass_name)
26
- klass = Object.qualified_const_get(controller_klass_name)
46
+ if specific_const_defined?(controller_klass_name)
47
+ klass = specific_const_get(controller_klass_name)
27
48
  else
28
- klass = Class.new(ApplicationController)
29
- Object.qualified_const_set(controller_klass_name, klass)
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
@@ -1,3 +1,3 @@
1
1
  module Ddc
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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.5
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: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler