descendants_describable 0.0.6 → 0.0.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: f75101f868e228a1224ee6fb1931fecb392028c8
4
- data.tar.gz: 11c1345d23630f39af49bc2ebce9283e6e61c8d7
3
+ metadata.gz: 75e1789e4082b1a6239f9bad3fb497729c83bc08
4
+ data.tar.gz: c08b66a1c6d403021970aafc5ec179514b911582
5
5
  SHA512:
6
- metadata.gz: 4275d6305681b8eced12139599463d57f94860d6c057a122019162497d4d9064f9ef7633eb055ba0f42225aa580b9540b08c457e3c4cdb424b9e8d8efe49d68f
7
- data.tar.gz: 0e88aeb50220bc4c487dac3aea91a9ab3b3566cae99d61803e35da233003c5d154decbda852c6f75604ebd709e418f5cbead01a898030459b2f2955c7a8a35ea
6
+ metadata.gz: 8277354cf0644d64455e0ec8f8cee4ffb4194418c185bca4aa43d59382329357bf3f468ab6d95eca8e169665ea896cb9879c6ac1fff2d7132e7cd4859b9ac148
7
+ data.tar.gz: 995a75860c2d8855682339b9b84d63acb3c55120642a2b8e45518b30f8da74d6701d42d69782a2a1b4f03bafb3087a173033403a1ab2af2cd35fb2c9014926cc
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ descendants_describable --create
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/README.md CHANGED
@@ -97,6 +97,12 @@ end
97
97
 
98
98
  ```
99
99
 
100
+ ## Note
101
+
102
+ You should put any calls to `describe_descendants_with` somewhere where it will only be executed
103
+ once per boot of your app (including code reloading), such as an initializer(s). This is because
104
+ each time you call `describe_descendants_with`, a hook is registered with Rails via
105
+ `ActiveSupport::Reloader.to_run`; you don't want to register duplicate reload hooks.
100
106
 
101
107
  ## Contributing
102
108
 
@@ -1,3 +1,3 @@
1
1
  module DescendantsDescribable
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -5,7 +5,10 @@ module DescendantsDescribable
5
5
 
6
6
  module ClassMethods
7
7
  def describe_descendants_with(description_module, &block)
8
- DescendantsDescriptor.new(self, description_module).instance_exec &block
8
+ descriptor = DescendantsDescriptor.new(self, description_module, block)
9
+ descriptor.describe_descendants
10
+ descriptor.register_reload_hook
11
+ descriptor
9
12
  end
10
13
  end
11
14
 
@@ -14,10 +17,38 @@ module DescendantsDescribable
14
17
 
15
18
  attr_accessor :new_class
16
19
 
17
- def initialize(parent, description_module)
20
+ def initialize(parent, description_module, description_proc)
18
21
  @common_modules = []
22
+ @descendant_names = []
19
23
  @parent = parent
20
24
  @description_module = description_module
25
+ @description_proc = description_proc
26
+ end
27
+
28
+ def describe_descendants
29
+ instance_exec(&@description_proc)
30
+ end
31
+
32
+ def undefine_descendants
33
+ @descendant_names.each do |descendant_name|
34
+ Object.send(:remove_const, descendant_name) if Object.const_defined?(descendant_name)
35
+ end
36
+ @descendant_names = []
37
+ end
38
+
39
+ def reload_parent
40
+ parent_name = @parent.name.to_sym
41
+ Object.send(:remove_const, parent_name) if Object.const_defined?(parent_name)
42
+ @parent = ActiveSupport::Dependencies.load_missing_constant(Object, parent_name)
43
+ end
44
+
45
+ def register_reload_hook
46
+ descriptor = self
47
+ ActiveSupport::Reloader.to_run do
48
+ descriptor.undefine_descendants
49
+ descriptor.reload_parent
50
+ descriptor.describe_descendants
51
+ end
21
52
  end
22
53
 
23
54
  def add_module(mod)
@@ -31,6 +62,7 @@ module DescendantsDescribable
31
62
  rescue NameError
32
63
  new_class = Class.new(@parent)
33
64
  Object.const_set(name.to_s.camelize, new_class)
65
+ @descendant_names << name.to_s.camelize.to_sym
34
66
  new_class
35
67
  end
36
68
 
@@ -55,4 +87,4 @@ module DescendantsDescribable
55
87
  @description_module.const_get(method.to_s.camelize) rescue false
56
88
  end
57
89
  end
58
- end
90
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: descendants_describable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - winfred
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -117,7 +117,8 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - ".gitignore"
120
- - ".rvmrc"
120
+ - ".ruby-gemset"
121
+ - ".ruby-version"
121
122
  - Gemfile
122
123
  - LICENSE.txt
123
124
  - README.md
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  version: '0'
149
150
  requirements: []
150
151
  rubyforge_project:
151
- rubygems_version: 2.2.2
152
+ rubygems_version: 2.6.12
152
153
  signing_key:
153
154
  specification_version: 4
154
155
  summary: Turn a module of behavioral concerns into a DSL for describing a large set
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm ruby-2.1.1@descendants_describable --create