smart_initializer 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +49 -53
- data/README.md +5 -0
- data/gemfiles/with_external_deps.gemfile.lock +51 -54
- data/gemfiles/without_external_deps.gemfile.lock +51 -52
- data/lib/smart_core/initializer/attribute/factory/base.rb +12 -3
- data/lib/smart_core/initializer/attribute/list.rb +19 -20
- data/lib/smart_core/initializer/constructor/definer.rb +13 -19
- data/lib/smart_core/initializer/dsl.rb +4 -3
- data/lib/smart_core/initializer/extensions/list.rb +11 -14
- data/lib/smart_core/initializer/plugins/abstract.rb +3 -1
- data/lib/smart_core/initializer/plugins/registry.rb +13 -14
- data/lib/smart_core/initializer/plugins/registry_interface.rb +11 -19
- data/lib/smart_core/initializer/settings/auto_cast.rb +5 -11
- data/lib/smart_core/initializer/settings/base.rb +5 -13
- data/lib/smart_core/initializer/settings/strict_options.rb +5 -11
- data/lib/smart_core/initializer/settings/type_system.rb +7 -16
- data/lib/smart_core/initializer/type_system/interop/aliasing/alias_list.rb +18 -21
- data/lib/smart_core/initializer/type_system/registry.rb +22 -24
- data/lib/smart_core/initializer/type_system/registry_interface.rb +15 -22
- data/lib/smart_core/initializer/version.rb +2 -2
- data/smart_initializer.gemspec +5 -5
- metadata +13 -13
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
class SmartCore::Initializer::Attribute::List
|
|
6
7
|
# @since 0.1.0
|
|
7
8
|
include Enumerable
|
|
@@ -10,9 +11,10 @@ class SmartCore::Initializer::Attribute::List
|
|
|
10
11
|
#
|
|
11
12
|
# @api private
|
|
12
13
|
# @since 0.1.0
|
|
14
|
+
# @version 0.10.0
|
|
13
15
|
def initialize
|
|
14
16
|
@attributes = {}
|
|
15
|
-
@lock = SmartCore::Engine::
|
|
17
|
+
@lock = SmartCore::Engine::ReadWriteLock.new
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# @param attribute_name [Symbol]
|
|
@@ -22,15 +24,16 @@ class SmartCore::Initializer::Attribute::List
|
|
|
22
24
|
#
|
|
23
25
|
# @api private
|
|
24
26
|
# @since 0.8.0
|
|
27
|
+
# @version 0.10.0
|
|
25
28
|
def fetch(attribute_name)
|
|
26
|
-
|
|
27
|
-
attributes.fetch(attribute_name)
|
|
28
|
-
rescue ::KeyError
|
|
29
|
+
@lock.read_sync do
|
|
29
30
|
raise(
|
|
30
31
|
::SmartCore::Initializer::UndefinedAttributeError,
|
|
31
32
|
"Attribute with `#{attribute_name}` name is not defined in your constructor. " \
|
|
32
33
|
"Please, check your attribute definitions inside your class."
|
|
33
|
-
)
|
|
34
|
+
) unless attributes.key?(attribute_name)
|
|
35
|
+
|
|
36
|
+
attributes[attribute_name]
|
|
34
37
|
end
|
|
35
38
|
end
|
|
36
39
|
alias_method :[], :fetch
|
|
@@ -40,8 +43,9 @@ class SmartCore::Initializer::Attribute::List
|
|
|
40
43
|
#
|
|
41
44
|
# @api private
|
|
42
45
|
# @since 0.1.0
|
|
46
|
+
# @version 0.10.0
|
|
43
47
|
def add(attribute)
|
|
44
|
-
|
|
48
|
+
@lock.write_sync { attributes[attribute.name] = attribute }
|
|
45
49
|
end
|
|
46
50
|
alias_method :<<, :add
|
|
47
51
|
|
|
@@ -50,8 +54,9 @@ class SmartCore::Initializer::Attribute::List
|
|
|
50
54
|
#
|
|
51
55
|
# @api private
|
|
52
56
|
# @since 0.1.0
|
|
57
|
+
# @version 0.10.0
|
|
53
58
|
def concat(list)
|
|
54
|
-
|
|
59
|
+
@lock.write_sync do
|
|
55
60
|
list.each { |attribute| add(attribute.dup) }
|
|
56
61
|
end
|
|
57
62
|
end
|
|
@@ -62,7 +67,7 @@ class SmartCore::Initializer::Attribute::List
|
|
|
62
67
|
# @api private
|
|
63
68
|
# @since 0.1.0
|
|
64
69
|
def include?(attribute)
|
|
65
|
-
|
|
70
|
+
@lock.read_sync { attributes.key?(attribute.name) }
|
|
66
71
|
end
|
|
67
72
|
|
|
68
73
|
# @param block [Block]
|
|
@@ -70,8 +75,9 @@ class SmartCore::Initializer::Attribute::List
|
|
|
70
75
|
#
|
|
71
76
|
# @api private
|
|
72
77
|
# @since 0.1.0
|
|
78
|
+
# @version 0.10.0
|
|
73
79
|
def each(&block)
|
|
74
|
-
|
|
80
|
+
@lock.read_sync do
|
|
75
81
|
block_given? ? attributes.values.each(&block) : attributes.values.each
|
|
76
82
|
end
|
|
77
83
|
end
|
|
@@ -80,8 +86,9 @@ class SmartCore::Initializer::Attribute::List
|
|
|
80
86
|
#
|
|
81
87
|
# @api private
|
|
82
88
|
# @since 0.1.0
|
|
89
|
+
# @version 0.10.0
|
|
83
90
|
def size
|
|
84
|
-
|
|
91
|
+
@lock.read_sync { attributes.size }
|
|
85
92
|
end
|
|
86
93
|
|
|
87
94
|
# @param block [Block]
|
|
@@ -89,8 +96,9 @@ class SmartCore::Initializer::Attribute::List
|
|
|
89
96
|
#
|
|
90
97
|
# @api private
|
|
91
98
|
# @since 0.1.0
|
|
99
|
+
# @version 0.10.0
|
|
92
100
|
def count(&block)
|
|
93
|
-
|
|
101
|
+
@lock.read_sync { attributes.values.count(&block) }
|
|
94
102
|
end
|
|
95
103
|
|
|
96
104
|
private
|
|
@@ -100,13 +108,4 @@ class SmartCore::Initializer::Attribute::List
|
|
|
100
108
|
# @api private
|
|
101
109
|
# @since 0.1.0
|
|
102
110
|
attr_reader :attributes
|
|
103
|
-
|
|
104
|
-
# @param block [Block]
|
|
105
|
-
# @return [Any]
|
|
106
|
-
#
|
|
107
|
-
# @api private
|
|
108
|
-
# @since 0.1.0
|
|
109
|
-
def thread_safe(&block)
|
|
110
|
-
@lock.synchronize(&block)
|
|
111
|
-
end
|
|
112
111
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
# rubocop:disable Metrics/ClassLength
|
|
6
7
|
class SmartCore::Initializer::Constructor::Definer
|
|
7
8
|
# @param klass [Class]
|
|
@@ -9,9 +10,10 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
9
10
|
#
|
|
10
11
|
# @api private
|
|
11
12
|
# @since 0.1.0
|
|
13
|
+
# @version 0.10.0
|
|
12
14
|
def initialize(klass)
|
|
13
15
|
@klass = klass
|
|
14
|
-
@lock = SmartCore::Engine::
|
|
16
|
+
@lock = SmartCore::Engine::ReadWriteLock.new
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# @param block [Proc]
|
|
@@ -19,8 +21,9 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
19
21
|
#
|
|
20
22
|
# @api private
|
|
21
23
|
# @since 0.1.0
|
|
24
|
+
# @version 0.10.0
|
|
22
25
|
def define_init_extension(block)
|
|
23
|
-
|
|
26
|
+
@lock.write_sync do
|
|
24
27
|
add_init_extension(build_init_extension(block))
|
|
25
28
|
end
|
|
26
29
|
end
|
|
@@ -37,7 +40,7 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
37
40
|
#
|
|
38
41
|
# @api private
|
|
39
42
|
# @since 0.1.0
|
|
40
|
-
# @version 0.
|
|
43
|
+
# @version 0.10.0
|
|
41
44
|
def define_parameter(
|
|
42
45
|
name,
|
|
43
46
|
type,
|
|
@@ -48,7 +51,7 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
48
51
|
mutable,
|
|
49
52
|
as
|
|
50
53
|
)
|
|
51
|
-
|
|
54
|
+
@lock.write_sync do
|
|
52
55
|
attribute = build_param_attribute(
|
|
53
56
|
name,
|
|
54
57
|
type,
|
|
@@ -71,9 +74,9 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
71
74
|
#
|
|
72
75
|
# @api private
|
|
73
76
|
# @since 0.1.0
|
|
74
|
-
# @version 0.
|
|
77
|
+
# @version 0.10.0
|
|
75
78
|
def define_parameters(*names, mutable:, privacy:)
|
|
76
|
-
|
|
79
|
+
@lock.write_sync do
|
|
77
80
|
names.map do |name|
|
|
78
81
|
build_param_attribute(
|
|
79
82
|
name,
|
|
@@ -107,7 +110,7 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
107
110
|
#
|
|
108
111
|
# @api private
|
|
109
112
|
# @since 0.1.0
|
|
110
|
-
# @version 0.
|
|
113
|
+
# @version 0.10.0
|
|
111
114
|
def define_option(
|
|
112
115
|
name,
|
|
113
116
|
type,
|
|
@@ -120,7 +123,7 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
120
123
|
default,
|
|
121
124
|
optional
|
|
122
125
|
)
|
|
123
|
-
|
|
126
|
+
@lock.write_sync do
|
|
124
127
|
attribute = build_option_attribute(
|
|
125
128
|
name,
|
|
126
129
|
type,
|
|
@@ -145,9 +148,9 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
145
148
|
#
|
|
146
149
|
# @api private
|
|
147
150
|
# @since 0.1.0
|
|
148
|
-
# @version 0.
|
|
151
|
+
# @version 0.10.0
|
|
149
152
|
def define_options(*names, mutable:, privacy:)
|
|
150
|
-
|
|
153
|
+
@lock.write_sync do
|
|
151
154
|
names.map do |name|
|
|
152
155
|
build_option_attribute(
|
|
153
156
|
name,
|
|
@@ -352,14 +355,5 @@ class SmartCore::Initializer::Constructor::Definer
|
|
|
352
355
|
ERROR_MESSAGE
|
|
353
356
|
end
|
|
354
357
|
end
|
|
355
|
-
|
|
356
|
-
# @param block [Block]
|
|
357
|
-
# @return [Any]
|
|
358
|
-
#
|
|
359
|
-
# @api private
|
|
360
|
-
# @since 0.1.0
|
|
361
|
-
def thread_safe(&block)
|
|
362
|
-
@lock.synchronize(&block)
|
|
363
|
-
end
|
|
364
358
|
end
|
|
365
359
|
# rubocop:enable Metrics/ClassLength
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
module SmartCore::Initializer::DSL
|
|
6
7
|
require_relative 'dsl/inheritance'
|
|
7
8
|
|
|
@@ -11,13 +12,13 @@ module SmartCore::Initializer::DSL
|
|
|
11
12
|
#
|
|
12
13
|
# @api private
|
|
13
14
|
# @since 0.1.0
|
|
15
|
+
# @version 0.10.0
|
|
14
16
|
def extended(base_klass)
|
|
15
17
|
base_klass.instance_eval do
|
|
16
18
|
instance_variable_set(:@__params__, SmartCore::Initializer::Attribute::List.new)
|
|
17
19
|
instance_variable_set(:@__options__, SmartCore::Initializer::Attribute::List.new)
|
|
18
20
|
instance_variable_set(:@__init_extensions__, SmartCore::Initializer::Extensions::List.new)
|
|
19
21
|
instance_variable_set(:@__definer__, SmartCore::Initializer::Constructor::Definer.new(self))
|
|
20
|
-
instance_variable_set(:@__deflock__, SmartCore::Engine::Lock.new)
|
|
21
22
|
instance_variable_set(:@__initializer_settings__, SmartCore::Initializer::Settings.new)
|
|
22
23
|
end
|
|
23
24
|
base_klass.extend(ClassMethods)
|
|
@@ -27,20 +28,20 @@ module SmartCore::Initializer::DSL
|
|
|
27
28
|
|
|
28
29
|
# @api private
|
|
29
30
|
# @since 0.1.0
|
|
31
|
+
# @version 0.10.0
|
|
30
32
|
module ClassInheritance
|
|
31
33
|
# @param child_klass [Class]
|
|
32
34
|
# @return [void]
|
|
33
35
|
#
|
|
34
36
|
# @api private
|
|
35
37
|
# @since 0.1.0
|
|
36
|
-
# @version 0.
|
|
38
|
+
# @version 0.10.0
|
|
37
39
|
def inherited(child_klass)
|
|
38
40
|
child_klass.instance_exec(__initializer_settings__) do |init_settings|
|
|
39
41
|
instance_variable_set(:@__params__, SmartCore::Initializer::Attribute::List.new)
|
|
40
42
|
instance_variable_set(:@__options__, SmartCore::Initializer::Attribute::List.new)
|
|
41
43
|
instance_variable_set(:@__init_extensions__, SmartCore::Initializer::Extensions::List.new)
|
|
42
44
|
instance_variable_set(:@__definer__, SmartCore::Initializer::Constructor::Definer.new(self))
|
|
43
|
-
instance_variable_set(:@__deflock__, SmartCore::Engine::Lock.new)
|
|
44
45
|
instance_variable_set(:@__initializer_settings__, init_settings.dup)
|
|
45
46
|
end
|
|
46
47
|
child_klass.extend(ClassMethods)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
class SmartCore::Initializer::Extensions::List
|
|
6
7
|
# @since 0.1.0
|
|
7
8
|
include Enumerable
|
|
@@ -10,9 +11,10 @@ class SmartCore::Initializer::Extensions::List
|
|
|
10
11
|
#
|
|
11
12
|
# @api private
|
|
12
13
|
# @since 0.1.0
|
|
14
|
+
# @version 0.10.0
|
|
13
15
|
def initialize
|
|
14
16
|
@extensions = []
|
|
15
|
-
@lock = SmartCore::Engine::
|
|
17
|
+
@lock = SmartCore::Engine::ReadWriteLock.new
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# @param extension [SmartCore::Initializer::Extensions::Abstract]
|
|
@@ -20,8 +22,9 @@ class SmartCore::Initializer::Extensions::List
|
|
|
20
22
|
#
|
|
21
23
|
# @api private
|
|
22
24
|
# @since 0.1.0
|
|
25
|
+
# @version 0.10.0
|
|
23
26
|
def add(extension)
|
|
24
|
-
|
|
27
|
+
@lock.write_sync { extensions << extension }
|
|
25
28
|
end
|
|
26
29
|
alias_method :<<, :add
|
|
27
30
|
|
|
@@ -30,8 +33,9 @@ class SmartCore::Initializer::Extensions::List
|
|
|
30
33
|
#
|
|
31
34
|
# @api private
|
|
32
35
|
# @since 0.1.0
|
|
36
|
+
# @version 0.10.0
|
|
33
37
|
def concat(list)
|
|
34
|
-
|
|
38
|
+
@lock.write_sync do
|
|
35
39
|
list.each { |extension| add(extension.dup) }
|
|
36
40
|
end
|
|
37
41
|
end
|
|
@@ -41,8 +45,9 @@ class SmartCore::Initializer::Extensions::List
|
|
|
41
45
|
#
|
|
42
46
|
# @api private
|
|
43
47
|
# @since 0.1.0
|
|
48
|
+
# @version 0.10.0
|
|
44
49
|
def each(&block)
|
|
45
|
-
|
|
50
|
+
@lock.read_sync do
|
|
46
51
|
block_given? ? extensions.each(&block) : extensions.each
|
|
47
52
|
end
|
|
48
53
|
end
|
|
@@ -51,8 +56,9 @@ class SmartCore::Initializer::Extensions::List
|
|
|
51
56
|
#
|
|
52
57
|
# @api private
|
|
53
58
|
# @since 0.1.0
|
|
59
|
+
# @version 0.10.0
|
|
54
60
|
def size
|
|
55
|
-
|
|
61
|
+
@lock.read_sync { extensions.size }
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
private
|
|
@@ -62,13 +68,4 @@ class SmartCore::Initializer::Extensions::List
|
|
|
62
68
|
# @api private
|
|
63
69
|
# @since 0.1.0
|
|
64
70
|
attr_reader :extensions
|
|
65
|
-
|
|
66
|
-
# @param block [Block]
|
|
67
|
-
# @return [Any]
|
|
68
|
-
#
|
|
69
|
-
# @api private
|
|
70
|
-
# @since 0.1.0
|
|
71
|
-
def thread_safe(&block)
|
|
72
|
-
@lock.synchronize(&block)
|
|
73
|
-
end
|
|
74
71
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
class SmartCore::Initializer::Plugins::Abstract
|
|
6
7
|
class << self
|
|
7
8
|
# @param child_klass [Class]
|
|
@@ -9,9 +10,10 @@ class SmartCore::Initializer::Plugins::Abstract
|
|
|
9
10
|
#
|
|
10
11
|
# @api private
|
|
11
12
|
# @since 0.1.0
|
|
13
|
+
# @version 0.10.0
|
|
12
14
|
def inherited(child_klass)
|
|
13
15
|
child_klass.instance_variable_set(:@__loaded__, false)
|
|
14
|
-
child_klass.instance_variable_set(:@__lock__,
|
|
16
|
+
child_klass.instance_variable_set(:@__lock__, SmartCore::Engine::Lock.new)
|
|
15
17
|
super
|
|
16
18
|
end
|
|
17
19
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
class SmartCore::Initializer::Plugins::Registry
|
|
6
7
|
# @since 0.1.0
|
|
7
8
|
include Enumerable
|
|
@@ -10,9 +11,10 @@ class SmartCore::Initializer::Plugins::Registry
|
|
|
10
11
|
#
|
|
11
12
|
# @api private
|
|
12
13
|
# @since 0.1.0
|
|
14
|
+
# @version 0.10.0
|
|
13
15
|
def initialize
|
|
14
16
|
@plugin_set = {}
|
|
15
|
-
@access_lock =
|
|
17
|
+
@access_lock = SmartCore::Engine::ReadWriteLock.new
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# @param plugin_name [Symbol, String]
|
|
@@ -20,8 +22,9 @@ class SmartCore::Initializer::Plugins::Registry
|
|
|
20
22
|
#
|
|
21
23
|
# @api private
|
|
22
24
|
# @since 0.1.0
|
|
25
|
+
# @version 0.10.0
|
|
23
26
|
def [](plugin_name)
|
|
24
|
-
|
|
27
|
+
@access_lock.read_sync { fetch(plugin_name) }
|
|
25
28
|
end
|
|
26
29
|
|
|
27
30
|
# @param plugin_name [Symbol, String]
|
|
@@ -30,8 +33,9 @@ class SmartCore::Initializer::Plugins::Registry
|
|
|
30
33
|
#
|
|
31
34
|
# @api private
|
|
32
35
|
# @since 0.1.0
|
|
36
|
+
# @version 0.10.0
|
|
33
37
|
def register(plugin_name, plugin_module)
|
|
34
|
-
|
|
38
|
+
@access_lock.write_sync { apply(plugin_name, plugin_module) }
|
|
35
39
|
end
|
|
36
40
|
alias_method :[]=, :register
|
|
37
41
|
|
|
@@ -39,16 +43,18 @@ class SmartCore::Initializer::Plugins::Registry
|
|
|
39
43
|
#
|
|
40
44
|
# @api private
|
|
41
45
|
# @since 0.1.0
|
|
46
|
+
# @version 0.10.0
|
|
42
47
|
def names
|
|
43
|
-
|
|
48
|
+
@access_lock.read_sync { plugin_names }
|
|
44
49
|
end
|
|
45
50
|
|
|
46
51
|
# @return [Hash<String,Class<SmartCore::Initializer::Plugins::Abstract>>]
|
|
47
52
|
#
|
|
48
53
|
# @api private
|
|
49
54
|
# @since 0.1.0
|
|
55
|
+
# @version 0.10.0
|
|
50
56
|
def loaded
|
|
51
|
-
|
|
57
|
+
@access_lock.read_sync { loaded_plugins }
|
|
52
58
|
end
|
|
53
59
|
|
|
54
60
|
# @param block [Block]
|
|
@@ -56,8 +62,9 @@ class SmartCore::Initializer::Plugins::Registry
|
|
|
56
62
|
#
|
|
57
63
|
# @api private
|
|
58
64
|
# @since 0.1.0
|
|
65
|
+
# @version 0.10.0
|
|
59
66
|
def each(&block)
|
|
60
|
-
|
|
67
|
+
@access_lock.read_sync { iterate(&block) }
|
|
61
68
|
end
|
|
62
69
|
|
|
63
70
|
private
|
|
@@ -74,14 +81,6 @@ class SmartCore::Initializer::Plugins::Registry
|
|
|
74
81
|
# @since 0.1.0
|
|
75
82
|
attr_reader :access_lock
|
|
76
83
|
|
|
77
|
-
# @return [void]
|
|
78
|
-
#
|
|
79
|
-
# @api private
|
|
80
|
-
# @since 0.1.0
|
|
81
|
-
def thread_safe
|
|
82
|
-
access_lock.synchronize { yield if block_given? }
|
|
83
|
-
end
|
|
84
|
-
|
|
85
84
|
# @return [Array<String>]
|
|
86
85
|
#
|
|
87
86
|
# @api private
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
module SmartCore::Initializer::Plugins::RegistryInterface
|
|
6
7
|
class << self
|
|
7
8
|
# @param base_module [Class, Module]
|
|
@@ -9,12 +10,13 @@ module SmartCore::Initializer::Plugins::RegistryInterface
|
|
|
9
10
|
#
|
|
10
11
|
# @api private
|
|
11
12
|
# @since 0.1.0
|
|
13
|
+
# @version 0.10.0
|
|
12
14
|
def extended(base_module)
|
|
13
15
|
base_module.instance_variable_set(
|
|
14
16
|
:@plugin_registry, SmartCore::Initializer::Plugins::Registry.new
|
|
15
17
|
)
|
|
16
18
|
base_module.instance_variable_set(
|
|
17
|
-
:@access_lock, SmartCore::Engine::
|
|
19
|
+
:@access_lock, SmartCore::Engine::ReadWriteLock.new
|
|
18
20
|
)
|
|
19
21
|
end
|
|
20
22
|
end
|
|
@@ -24,24 +26,27 @@ module SmartCore::Initializer::Plugins::RegistryInterface
|
|
|
24
26
|
#
|
|
25
27
|
# @api public
|
|
26
28
|
# @since 0.1.0
|
|
29
|
+
# @version 0.10.0
|
|
27
30
|
def load(plugin_name)
|
|
28
|
-
|
|
31
|
+
@access_lock.read_sync { plugin_registry[plugin_name].load! }
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
# @return [Array<String>]
|
|
32
35
|
#
|
|
33
36
|
# @api public
|
|
34
37
|
# @since 0.1.0
|
|
38
|
+
# @version 0.10.0
|
|
35
39
|
def loaded_plugins
|
|
36
|
-
|
|
40
|
+
@access_lock.read_sync { plugin_registry.loaded.keys }
|
|
37
41
|
end
|
|
38
42
|
|
|
39
43
|
# @return [Array<String>]
|
|
40
44
|
#
|
|
41
45
|
# @api public
|
|
42
46
|
# @since 0.1.0
|
|
47
|
+
# @version 0.10.0
|
|
43
48
|
def names
|
|
44
|
-
|
|
49
|
+
@access_lock.read_sync { plugin_registry.names }
|
|
45
50
|
end
|
|
46
51
|
|
|
47
52
|
# @param plugin_name [Symbol, String]
|
|
@@ -49,8 +54,9 @@ module SmartCore::Initializer::Plugins::RegistryInterface
|
|
|
49
54
|
#
|
|
50
55
|
# @api private
|
|
51
56
|
# @since 0.1.0
|
|
57
|
+
# @version 0.10.0
|
|
52
58
|
def register_plugin(plugin_name, plugin_module)
|
|
53
|
-
|
|
59
|
+
@access_lock.write_sync { plugin_registry[plugin_name] = plugin_module }
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
private
|
|
@@ -60,18 +66,4 @@ module SmartCore::Initializer::Plugins::RegistryInterface
|
|
|
60
66
|
# @api private
|
|
61
67
|
# @since 0.1.0
|
|
62
68
|
attr_reader :plugin_registry
|
|
63
|
-
|
|
64
|
-
# @return [SmartCore::Engine::Lock]
|
|
65
|
-
#
|
|
66
|
-
# @api private
|
|
67
|
-
# @since 0.1.0
|
|
68
|
-
attr_reader :access_lock
|
|
69
|
-
|
|
70
|
-
# @return [void]
|
|
71
|
-
#
|
|
72
|
-
# @api private
|
|
73
|
-
# @since 0.1.0
|
|
74
|
-
def thread_safe
|
|
75
|
-
access_lock.synchronize { yield if block_given? }
|
|
76
|
-
end
|
|
77
69
|
end
|
|
@@ -2,22 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.8.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
class SmartCore::Initializer::Settings::AutoCast < SmartCore::Initializer::Settings::Base
|
|
6
|
-
# @return [void]
|
|
7
|
-
#
|
|
8
|
-
# @api private
|
|
9
|
-
# @since 0.8.0
|
|
10
|
-
def initialize
|
|
11
|
-
@value = nil
|
|
12
|
-
@lock = SmartCore::Engine::Lock.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
7
|
# @return [Boolean]
|
|
16
8
|
#
|
|
17
9
|
# @api private
|
|
18
10
|
# @since 0.8.0
|
|
11
|
+
# @version 0.10.0
|
|
19
12
|
def resolve
|
|
20
|
-
|
|
13
|
+
@lock.read_sync do
|
|
21
14
|
@value == nil ? SmartCore::Initializer::Configuration[:auto_cast] : @value
|
|
22
15
|
end
|
|
23
16
|
end
|
|
@@ -27,8 +20,9 @@ class SmartCore::Initializer::Settings::AutoCast < SmartCore::Initializer::Setti
|
|
|
27
20
|
#
|
|
28
21
|
# @api private
|
|
29
22
|
# @since 0.8.0
|
|
23
|
+
# @version 0.10.0
|
|
30
24
|
def assign(value)
|
|
31
|
-
|
|
25
|
+
@lock.write_sync do
|
|
32
26
|
raise(
|
|
33
27
|
SmartCore::Initializer::SettingArgumentError,
|
|
34
28
|
":auto_cast setting should be a type of boolean (got: `#{value.class}`)"
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.8.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
class SmartCore::Initializer::Settings::Base
|
|
6
7
|
# @return [void]
|
|
7
8
|
#
|
|
8
9
|
# @api private
|
|
9
10
|
# @since 0.8.0
|
|
11
|
+
# @version 0.10.0
|
|
10
12
|
def initialize
|
|
11
13
|
@value = nil
|
|
12
|
-
@lock = SmartCore::Engine::
|
|
14
|
+
@lock = SmartCore::Engine::ReadWriteLock.new
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
# @!method resolve
|
|
@@ -28,22 +30,12 @@ class SmartCore::Initializer::Settings::Base
|
|
|
28
30
|
#
|
|
29
31
|
# @api private
|
|
30
32
|
# @since 0.8.0
|
|
33
|
+
# @version 0.10.0
|
|
31
34
|
def dup
|
|
32
|
-
|
|
35
|
+
@lock.write_sync do
|
|
33
36
|
self.class.new.tap do |duplicate|
|
|
34
37
|
duplicate.instance_variable_set(:@value, @value)
|
|
35
38
|
end
|
|
36
39
|
end
|
|
37
40
|
end
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
# @param block [Block]
|
|
42
|
-
# @return [Any]
|
|
43
|
-
#
|
|
44
|
-
# @api private
|
|
45
|
-
# @since 0.8.0
|
|
46
|
-
def thread_safe(&block)
|
|
47
|
-
@lock.synchronize(&block)
|
|
48
|
-
end
|
|
49
41
|
end
|
|
@@ -2,22 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.8.0
|
|
5
|
+
# @version 0.10.0
|
|
5
6
|
class SmartCore::Initializer::Settings::StrictOptions < SmartCore::Initializer::Settings::Base
|
|
6
|
-
# @return [void]
|
|
7
|
-
#
|
|
8
|
-
# @api private
|
|
9
|
-
# @since 0.8.0
|
|
10
|
-
def initialize
|
|
11
|
-
@value = nil
|
|
12
|
-
@lock = SmartCore::Engine::Lock.new
|
|
13
|
-
end
|
|
14
|
-
|
|
15
7
|
# @return [Boolean]
|
|
16
8
|
#
|
|
17
9
|
# @api private
|
|
18
10
|
# @since 0.8.0
|
|
11
|
+
# @version 0.10.0
|
|
19
12
|
def resolve
|
|
20
|
-
|
|
13
|
+
@lock.read_sync do
|
|
21
14
|
@value == nil ? SmartCore::Initializer::Configuration[:strict_options] : @value
|
|
22
15
|
end
|
|
23
16
|
end
|
|
@@ -27,8 +20,9 @@ class SmartCore::Initializer::Settings::StrictOptions < SmartCore::Initializer::
|
|
|
27
20
|
#
|
|
28
21
|
# @api private
|
|
29
22
|
# @since 0.8.0
|
|
23
|
+
# @version 0.10.0
|
|
30
24
|
def assign(value)
|
|
31
|
-
|
|
25
|
+
@lock.write_sync do
|
|
32
26
|
raise(
|
|
33
27
|
SmartCore::Initializer::SettingArgumentError,
|
|
34
28
|
":strict_options setting should be a type of boolean (got: `#{value.class}`)"
|
|
@@ -2,24 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 0.1.0
|
|
5
|
-
# @version 0.
|
|
5
|
+
# @version 0.10.0
|
|
6
6
|
class SmartCore::Initializer::Settings::TypeSystem < SmartCore::Initializer::Settings::Base
|
|
7
|
-
# @return [void]
|
|
8
|
-
#
|
|
9
|
-
# @api private
|
|
10
|
-
# @since 0.1.0
|
|
11
|
-
# @version 0.8.0
|
|
12
|
-
def initialize
|
|
13
|
-
@value = nil
|
|
14
|
-
@lock = SmartCore::Engine::Lock.new
|
|
15
|
-
end
|
|
16
|
-
|
|
17
7
|
# @return [Any]
|
|
18
8
|
#
|
|
19
9
|
# @api private
|
|
20
10
|
# @since 0.1.0
|
|
11
|
+
# @version 0.10.0
|
|
21
12
|
def generic_type_object
|
|
22
|
-
|
|
13
|
+
@lock.read_sync do
|
|
23
14
|
SmartCore::Initializer::TypeSystem.resolve(resolve).generic_type_object
|
|
24
15
|
end
|
|
25
16
|
end
|
|
@@ -28,9 +19,9 @@ class SmartCore::Initializer::Settings::TypeSystem < SmartCore::Initializer::Set
|
|
|
28
19
|
#
|
|
29
20
|
# @api private
|
|
30
21
|
# @since 0.1.0
|
|
31
|
-
# @version 0.
|
|
22
|
+
# @version 0.10.0
|
|
32
23
|
def resolve
|
|
33
|
-
|
|
24
|
+
@lock.read_sync do
|
|
34
25
|
@value == nil ? SmartCore::Initializer::Configuration[:default_type_system] : @value
|
|
35
26
|
end
|
|
36
27
|
end
|
|
@@ -40,9 +31,9 @@ class SmartCore::Initializer::Settings::TypeSystem < SmartCore::Initializer::Set
|
|
|
40
31
|
#
|
|
41
32
|
# @api private
|
|
42
33
|
# @since 0.1.0
|
|
43
|
-
# @version 0.
|
|
34
|
+
# @version 0.10.0
|
|
44
35
|
def assign(value)
|
|
45
|
-
|
|
36
|
+
@lock.write_sync do
|
|
46
37
|
# NOTE: type system existence validation
|
|
47
38
|
SmartCore::Initializer::TypeSystem.resolve(value)
|
|
48
39
|
@value = value
|