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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c564713e7662f0a43698d26b54a62518f160a3b54106d880d8600de692999983
4
- data.tar.gz: ff04516a334e4a3b56a05215d0093468d9c400f3aedf09dec7e48019997ff1cb
3
+ metadata.gz: 51385491182124c0f1e675f1df90d7e81f3e84f8324b665720da9a67a037acff
4
+ data.tar.gz: 5212e853afa9c4eefe2039716b1f8438c9dda7ed105a0c65f0202c13b47f8032
5
5
  SHA512:
6
- metadata.gz: a0e25cd5f217bf740c33cf061d0247aec276e7a39fd6a78ea5dec0da70d4d8166b82e8f52c84e0b4d57403622f090b44f99f8a11dde28f1730ab7818291523cc
7
- data.tar.gz: ea9e18a2d11e640e705c7f523028ec08efba5c2b16d74933d870b98f3815eea532cfa037c034c70af10af9dedd26626687334fe0a3d4eab4d888121f1c059daf
6
+ metadata.gz: 2001883e0fee53b47f8259a3d74bf70ab5c1b41ebb5427e72a496ba28940b722a4c10f1430fb6a826946eb55b988ce2d8f6fc8740f081fd5fe91e380d5b91c57
7
+ data.tar.gz: 14919ff5da8885b09e3b315cc85fe211ae44972e516bd9da1ba49090bd4cfc9fd64e49ddb8984c0a7058b4776872ee6e9ff86a22e1d9bcbd564b746b4525e2b6
@@ -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.specialized_substitute_attr = new
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 NoSubstitute
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 :specialized_substitute_attr, Dependency::Example
6
+ subst_attr :null_object_substitute_attr
7
7
 
8
- subst_attr :strict_substitute_attr, Dependency::NoSubstitute::Example
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 :weak_substitute_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 :some_attr, Dependency::Example::Descendant
24
+ subst_attr :some_dependency_attr, Dependency::Example::Descendant
23
25
  end
24
26
  end
25
27
  end
@@ -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
- module NullObject
4
- extend self
5
-
6
- def build(interface=nil)
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 interface
7
- specialization = specialization(interface)
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
- return NullObject.build(interface)
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 specialization(interface)
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
- specialization_module = reflection.constant
54
+ mod = reflection.constant
31
55
 
32
- if specialization_module.equal?(self)
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
- unless specialization_module.respond_to?(:build)
37
- return nil
38
- end
63
+ mod
64
+ end
39
65
 
40
- specialization_module.send(:build)
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.2.0.0
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: 2021-07-26 00:00:00.000000000 Z
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.2.15
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 substitutes
110
- or null objects
109
+ summary: Declare attributes that have default implementations that are diagnostic
110
+ substitutes or null objects
111
111
  test_files: []