conscious_concern 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/conscious_concern/eager_loader.rb +13 -6
- data/lib/conscious_concern.rb +9 -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: 4b4762f0424331980889ae31c77792522a04f3d5
|
4
|
+
data.tar.gz: 2803f7a3a4d4ea421ff55af59f8e8a7d0621407c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a75f822b95413e5ffcb32f0d23197a12c9a1a4e9dbd706b36fb6f6342855669c8c9d40507c529a61049860ad83171c50b4918526e4e793bde68aeba798dd027
|
7
|
+
data.tar.gz: 04412680eb6aa2e7f46855ba5d7e79820bec6c36302d0a214e4c73108d07e5f4a18e3eac6bd87942f88474a702f8d1894a22453159d781bc5fe44101aeeac594
|
@@ -5,13 +5,19 @@ module ConsciousConcern
|
|
5
5
|
class EagerLoader
|
6
6
|
class_attribute :debug
|
7
7
|
|
8
|
-
def self.
|
8
|
+
def self.load_classes_in_rails_dirs(*dir_names)
|
9
9
|
rails = Object.const_defined?('Rails') ? 'Rails'.constantize : nil
|
10
10
|
unless rails && rails.root
|
11
11
|
puts 'no initialized Rails application' if debug
|
12
12
|
return false
|
13
13
|
end
|
14
|
-
|
14
|
+
load_classes_in_engine_dirs(rails, *dir_names)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load_classes_in_engine_dirs(engine, *dir_names)
|
18
|
+
dir_names.each do |dir_name|
|
19
|
+
load_classes_in_dir(engine.root.join('app', dir_name))
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def self.load_classes_in_dir(dir)
|
@@ -27,15 +33,16 @@ module ConsciousConcern
|
|
27
33
|
end
|
28
34
|
|
29
35
|
def self.load_class_at_path(path)
|
30
|
-
#
|
36
|
+
# Silence harmless 'already initialized constant' warnings that might
|
31
37
|
# occur due to Rails autoload having previously loaded some constants.
|
38
|
+
# Use load if require returns false for reloads in Rails development.
|
32
39
|
silence_warnings do
|
33
|
-
|
40
|
+
load path
|
34
41
|
puts "eager loaded class at #{path}" if debug
|
35
42
|
end
|
36
|
-
rescue LoadError, StandardError => e
|
43
|
+
rescue LoadError, StandardError, TypeError => e
|
37
44
|
return puts(e.message) if debug
|
38
|
-
raise e
|
45
|
+
raise e if e.message !~ /(previous def|define multiple|class mismatch)/
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
data/lib/conscious_concern.rb
CHANGED
@@ -3,18 +3,21 @@
|
|
3
3
|
#
|
4
4
|
module ConsciousConcern
|
5
5
|
require_relative File.join('conscious_concern', 'eager_loader')
|
6
|
+
require 'set'
|
6
7
|
require 'active_support/concern'
|
7
8
|
include ActiveSupport::Concern
|
8
9
|
|
9
|
-
def self.load_classes(*custom_dirs)
|
10
|
-
|
11
|
-
|
10
|
+
def self.load_classes(*custom_dirs, engine: nil, rails: true)
|
11
|
+
std_dirs = %w(controllers models)
|
12
|
+
EagerLoader.load_classes_in_engine_dirs(engine, *std_dirs) if engine
|
13
|
+
EagerLoader.load_classes_in_rails_dirs(*std_dirs) if rails
|
12
14
|
custom_dirs.each { |dir| EagerLoader.load_classes_in_dir(dir) }
|
15
|
+
|
13
16
|
extenders.each { |concern| concern._classes_loaded_callbacks.each(&:call) }
|
14
17
|
end
|
15
18
|
|
16
19
|
def self.extenders
|
17
|
-
@
|
20
|
+
@_extenders ||= Set.new
|
18
21
|
end
|
19
22
|
|
20
23
|
def self.extended(base)
|
@@ -24,7 +27,7 @@ module ConsciousConcern
|
|
24
27
|
|
25
28
|
def included(base = nil, &block)
|
26
29
|
_classes << base if base && base.is_a?(Class)
|
27
|
-
super
|
30
|
+
super unless base.nil? && instance_variable_defined?(:@_included_block)
|
28
31
|
end
|
29
32
|
|
30
33
|
def prepended(base = nil)
|
@@ -35,7 +38,7 @@ module ConsciousConcern
|
|
35
38
|
# underscore aliases protect core functionality against overrides in extenders
|
36
39
|
|
37
40
|
def classes
|
38
|
-
@_classes ||=
|
41
|
+
@_classes ||= Set.new
|
39
42
|
end
|
40
43
|
alias_method :_classes, :classes
|
41
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conscious_concern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janosch Müller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|