evt-subst_attr 2.1.0.3 → 2.3.0.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
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,18 +3,34 @@ 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
|
10
10
|
def self.build
|
11
|
-
:
|
11
|
+
:some_substitute
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
class Descendant < Example
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
module NoSubstituteModule
|
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
|
32
|
+
end
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
20
36
|
end
|
@@ -3,9 +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
|
11
|
+
|
12
|
+
subst_attr :constructed_substitute_attr, Dependency::Example
|
9
13
|
|
10
14
|
def self.build
|
11
15
|
new.tap do |instance|
|
@@ -17,7 +21,7 @@ module SubstAttr
|
|
17
21
|
class Example
|
18
22
|
include SubstAttr
|
19
23
|
|
20
|
-
subst_attr :
|
24
|
+
subst_attr :some_dependency_attr, Dependency::Example::Descendant
|
21
25
|
end
|
22
26
|
end
|
23
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,13 +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
|
-
|
63
|
+
mod
|
64
|
+
end
|
65
|
+
|
66
|
+
module Defaults
|
67
|
+
def self.record
|
68
|
+
true
|
69
|
+
end
|
37
70
|
end
|
38
71
|
end
|
39
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: []
|