evt-subst_attr 2.2.0.0 → 2.3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subst_attr/attribute.rb +2 -2
- data/lib/subst_attr/controls/dependency.rb +13 -2
- data/lib/subst_attr/controls/example.rb +6 -4
- data/lib/subst_attr/macro.rb +2 -2
- data/lib/subst_attr/substitute/null_object.rb +6 -18
- data/lib/subst_attr/substitute.rb +41 -12
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51385491182124c0f1e675f1df90d7e81f3e84f8324b665720da9a67a037acff
|
4
|
+
data.tar.gz: 5212e853afa9c4eefe2039716b1f8438c9dda7ed105a0c65f0202c13b47f8032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2001883e0fee53b47f8259a3d74bf70ab5c1b41ebb5427e72a496ba28940b722a4c10f1430fb6a826946eb55b988ce2d8f6fc8740f081fd5fe91e380d5b91c57
|
7
|
+
data.tar.gz: 14919ff5da8885b09e3b315cc85fe211ae44972e516bd9da1ba49090bd4cfc9fd64e49ddb8984c0a7058b4776872ee6e9ff86a22e1d9bcbd564b746b4525e2b6
|
data/lib/subst_attr/attribute.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module SubstAttr
|
2
2
|
module Attribute
|
3
|
-
def self.define(target_class, attr_name, interface=nil)
|
3
|
+
def self.define(target_class, attr_name, interface=nil, record=nil)
|
4
4
|
::Attribute::Define.(target_class, attr_name, :accessor) do
|
5
|
-
Substitute.build(interface)
|
5
|
+
Substitute.build(interface, record)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -3,7 +3,7 @@ module SubstAttr
|
|
3
3
|
module Dependency
|
4
4
|
class Example
|
5
5
|
def self.configure(receiver)
|
6
|
-
receiver.
|
6
|
+
receiver.constructed_substitute_attr = new
|
7
7
|
end
|
8
8
|
|
9
9
|
module Substitute
|
@@ -16,8 +16,19 @@ module SubstAttr
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
module
|
19
|
+
module NoSubstituteModule
|
20
20
|
class Example
|
21
|
+
def some_method
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module MixinSubstitute
|
27
|
+
class Example
|
28
|
+
module Substitute
|
29
|
+
def some_method
|
30
|
+
end
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
23
34
|
end
|
@@ -3,11 +3,13 @@ module SubstAttr
|
|
3
3
|
class Example
|
4
4
|
include SubstAttr
|
5
5
|
|
6
|
-
subst_attr :
|
6
|
+
subst_attr :null_object_substitute_attr
|
7
7
|
|
8
|
-
subst_attr :
|
8
|
+
subst_attr :mimic_substitute_attr, Dependency::NoSubstituteModule::Example
|
9
|
+
subst_attr :no_recorder_mimic_substitute_attr, Dependency::NoSubstituteModule::Example, record: false
|
10
|
+
subst_attr :mixed_in_mimic_substitute_attr, Dependency::MixinSubstitute::Example
|
9
11
|
|
10
|
-
subst_attr :
|
12
|
+
subst_attr :constructed_substitute_attr, Dependency::Example
|
11
13
|
|
12
14
|
def self.build
|
13
15
|
new.tap do |instance|
|
@@ -19,7 +21,7 @@ module SubstAttr
|
|
19
21
|
class Example
|
20
22
|
include SubstAttr
|
21
23
|
|
22
|
-
subst_attr :
|
24
|
+
subst_attr :some_dependency_attr, Dependency::Example::Descendant
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
data/lib/subst_attr/macro.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module SubstAttr
|
2
2
|
module Macro
|
3
|
-
def subst_attr_macro(attr_name, interface=nil)
|
4
|
-
SubstAttr::Attribute.define(self, attr_name, interface)
|
3
|
+
def subst_attr_macro(attr_name, interface=nil, record: nil)
|
4
|
+
SubstAttr::Attribute.define(self, attr_name, interface, record)
|
5
5
|
end
|
6
6
|
alias :subst_attr :subst_attr_macro
|
7
7
|
end
|
@@ -1,28 +1,16 @@
|
|
1
1
|
module SubstAttr
|
2
2
|
module Substitute
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
if interface
|
8
|
-
return strict(interface)
|
3
|
+
def self.null_object_class
|
4
|
+
Mimic::Build.(Object, record: false) do
|
5
|
+
def self.build
|
6
|
+
new
|
9
7
|
end
|
10
8
|
|
11
|
-
weak
|
12
|
-
end
|
13
|
-
|
14
|
-
def strict(interface)
|
15
|
-
Mimic.(interface, record: false)
|
16
|
-
end
|
17
|
-
|
18
|
-
def weak
|
19
|
-
Weak.new
|
20
|
-
end
|
21
|
-
|
22
|
-
Weak = Mimic::Build.(Object, record: false) do
|
23
9
|
def method_missing(*)
|
24
10
|
end
|
25
11
|
end
|
26
12
|
end
|
13
|
+
|
14
|
+
NullObject = Class.new(null_object_class)
|
27
15
|
end
|
28
16
|
end
|
@@ -2,13 +2,37 @@ module SubstAttr
|
|
2
2
|
module Substitute
|
3
3
|
extend self
|
4
4
|
|
5
|
-
def build(interface=nil)
|
6
|
-
if
|
7
|
-
|
8
|
-
return specialization if specialization
|
5
|
+
def build(interface=nil, record=nil)
|
6
|
+
if record.nil?
|
7
|
+
record = Defaults.record
|
9
8
|
end
|
10
9
|
|
11
|
-
|
10
|
+
if interface.nil?
|
11
|
+
return NullObject.build
|
12
|
+
end
|
13
|
+
|
14
|
+
substitute_module = substitute_module(interface)
|
15
|
+
|
16
|
+
if substitute_module.nil?
|
17
|
+
return mimic(interface, record)
|
18
|
+
end
|
19
|
+
|
20
|
+
if substitute_module.respond_to?(:build)
|
21
|
+
return substitute_module.send(:build)
|
22
|
+
end
|
23
|
+
|
24
|
+
mimic = mimic(interface, record)
|
25
|
+
mimic.extend(substitute_module)
|
26
|
+
|
27
|
+
mimic
|
28
|
+
end
|
29
|
+
|
30
|
+
def null_object
|
31
|
+
NullObject.build
|
32
|
+
end
|
33
|
+
|
34
|
+
def mimic(interface, record)
|
35
|
+
Mimic.(interface, record: record)
|
12
36
|
end
|
13
37
|
|
14
38
|
def call(attr_name, receiver)
|
@@ -18,7 +42,7 @@ module SubstAttr
|
|
18
42
|
substitute
|
19
43
|
end
|
20
44
|
|
21
|
-
def
|
45
|
+
def substitute_module(interface)
|
22
46
|
constant_name = :Substitute
|
23
47
|
|
24
48
|
reflection = Reflect.(interface, constant_name, strict: false, ancestors: true)
|
@@ -27,17 +51,22 @@ module SubstAttr
|
|
27
51
|
return nil
|
28
52
|
end
|
29
53
|
|
30
|
-
|
54
|
+
mod = reflection.constant
|
31
55
|
|
32
|
-
|
56
|
+
# Special case:
|
57
|
+
# Including Substitute puts SubstAttr::Substitute
|
58
|
+
# in the constant lookup class
|
59
|
+
if mod.equal?(self)
|
33
60
|
return nil
|
34
61
|
end
|
35
62
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
63
|
+
mod
|
64
|
+
end
|
39
65
|
|
40
|
-
|
66
|
+
module Defaults
|
67
|
+
def self.record
|
68
|
+
true
|
69
|
+
end
|
41
70
|
end
|
42
71
|
end
|
43
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evt-subst_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Eventide Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evt-attribute
|
@@ -103,9 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.4.6
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
|
-
summary: Declare attributes that have default implementations that are
|
110
|
-
or null objects
|
109
|
+
summary: Declare attributes that have default implementations that are diagnostic
|
110
|
+
substitutes or null objects
|
111
111
|
test_files: []
|