evt-record_invocation 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: adfb4397c17f13ed1113c3691483dc177ab698453211159165fb18d6803dcfae
4
+ data.tar.gz: ed0b2e87651eb4e475ba5e40d7baa8bb7d9c77bb2f7fbaa2e465a4386fe4ff3b
5
+ SHA512:
6
+ metadata.gz: 4fef722f260ad10b9538f5a7d97c218141ebd3c4cd988dfd0e409d1276e473496520936c99673757fe3b1637483a0f95cc9eac163b197de14ae41ebc35ed3466
7
+ data.tar.gz: 2f28cd0c551e6bc8678419d2df04198d4de01da95dab2e6d441b3ec0865ee6845c46f46382e204bbe80ec291fe1d79e8e7fd6ffecfbbba39e9f0817d0cfb9fdc
@@ -0,0 +1,19 @@
1
+ module RecordInvocation
2
+ module Controls
3
+ module Invocation
4
+ def self.example
5
+ parameters = {}
6
+ parameters[:some_parameter] = 1
7
+ parameters[:some_other_parameter] = 11
8
+
9
+ invocation = ::Invocation.new(method_name, parameters)
10
+
11
+ invocation
12
+ end
13
+
14
+ def self.method_name
15
+ :some_method
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ module RecordInvocation
2
+ module Controls
3
+ module Recorder
4
+ def self.example
5
+ Example.new
6
+ end
7
+
8
+ class Example
9
+ include ::RecordInvocation
10
+
11
+ def some_method
12
+ record_invocation(binding)
13
+ end
14
+ end
15
+
16
+ module RecordMacro
17
+ def self.example
18
+ Example.new
19
+ end
20
+
21
+ class Example
22
+ include ::RecordInvocation
23
+
24
+ record def some_recorded_method(
25
+ some_parameter,
26
+ some_optional_parameter=nil,
27
+ *some_multiple_assignment_parameter,
28
+ some_keyword_parameter:,
29
+ some_optional_keyword_parameter: nil,
30
+ **some_multiple_assignment_keyword_parameter,
31
+ &some_block
32
+ )
33
+ :some_result
34
+ end
35
+ end
36
+
37
+ module IgnoredParameters
38
+ def self.example
39
+ Example.new
40
+ end
41
+
42
+ class Example
43
+ include ::RecordInvocation
44
+
45
+ record def some_recorded_method(
46
+ *,
47
+ **,
48
+ &
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,2 @@
1
+ require 'record_invocation/controls/recorder'
2
+ require 'record_invocation/controls/invocation'
@@ -0,0 +1,153 @@
1
+ module RecordInvocation
2
+ Error = ::Class.new(RuntimeError)
3
+
4
+ def self.included(cls)
5
+ cls.class_exec do
6
+ extend Record
7
+ end
8
+ end
9
+
10
+ def __records
11
+ @__records ||= []
12
+ end
13
+ alias :records :__records
14
+
15
+ def __record(invocation)
16
+ __records << invocation
17
+ records
18
+ end
19
+ alias :record :__record
20
+
21
+ def __record_invocation(invocation_or_binding)
22
+ if invocation_or_binding.is_a?(Binding)
23
+ invocation = Invocation.build(invocation_or_binding)
24
+ end
25
+
26
+ __record(invocation)
27
+ invocation
28
+ end
29
+ alias :record_invocation :__record_invocation
30
+
31
+ def __invocation(method_name, **parameters)
32
+ strict = parameters.delete(:strict)
33
+ strict ||= false
34
+
35
+ invocations = __invocations(method_name, **parameters)
36
+
37
+ if invocations.empty?
38
+ return nil
39
+ end
40
+
41
+ if strict && invocations.length > 1
42
+ raise Error, "More than one invocation record matches (Method Name: #{method_name.inspect}, Parameters: #{parameters.inspect})"
43
+ end
44
+
45
+ invocations.first
46
+ end
47
+ alias :invocation :__invocation
48
+
49
+ def __one_invocation(method_name, **parameters)
50
+ parameters[:strict] = true
51
+ __invocation(method_name, **parameters)
52
+ end
53
+ alias :one_invocation :__one_invocation
54
+
55
+ def __invocations(method_name=nil, **parameters)
56
+ if method_name.nil? && parameters.empty?
57
+ return __records
58
+ end
59
+
60
+ invocations = __records.select { |invocation| invocation.method_name == method_name }
61
+
62
+ if parameters.nil?
63
+ return invocations
64
+ end
65
+
66
+ if invocations.empty?
67
+ return []
68
+ end
69
+
70
+ invocations = invocations.select do |invocation|
71
+ parameters.all? do |match_parameter_name, match_parameter_value|
72
+ invocation_value = invocation.arguments[match_parameter_name]
73
+
74
+ invocation_value == match_parameter_value
75
+ end
76
+ end
77
+
78
+ invocations
79
+ end
80
+ alias :invocations :__invocations
81
+
82
+ def __invoked?(method_name=nil, **parameters)
83
+ if method_name.nil? && parameters.empty?
84
+ return !__records.empty?
85
+ end
86
+
87
+ if not parameters.key?(:strict)
88
+ parameters[:strict] = false
89
+ end
90
+
91
+ invocation = __invocation(method_name, **parameters)
92
+ !invocation.nil?
93
+ end
94
+ alias :invoked? :__invoked?
95
+
96
+ def __invoked_once?(method_name, **parameters)
97
+ parameters[:strict] = true
98
+ __invoked?(method_name, **parameters)
99
+ end
100
+ alias :invoked_once? :__invoked_once?
101
+
102
+ module Record
103
+ def record_module
104
+ @record_module ||= prepend_record_module
105
+ end
106
+
107
+ def prepend_record_module
108
+ mod = Module.new
109
+ prepend mod
110
+ mod
111
+ end
112
+
113
+ def record_macro(method_name, &blk)
114
+ record_module.define_method(method_name) do |*args, **kwargs, &block|
115
+ parameters = method(method_name).super_method.parameters
116
+
117
+ positional_arguments = args.dup
118
+ keyword_arguments = kwargs.dup
119
+
120
+ arguments = {}
121
+
122
+ parameters.each do |type, name|
123
+ case type
124
+ when :req, :opt
125
+ if positional_arguments.any?
126
+ arguments[name] = positional_arguments.shift
127
+ end
128
+ when :rest
129
+ if positional_arguments.any?
130
+ arguments[name] = positional_arguments
131
+ end
132
+ when :key, :keyreq
133
+ if keyword_arguments.key?(name)
134
+ arguments[name] = keyword_arguments.delete(name)
135
+ end
136
+ when :keyrest
137
+ arguments[name] = keyword_arguments
138
+ when :block
139
+ if not block.nil?
140
+ arguments[name] = block
141
+ end
142
+ end
143
+ end
144
+
145
+ invocation = Invocation.new(method_name, arguments)
146
+ __record(invocation)
147
+
148
+ super(*args, **kwargs, &block)
149
+ end
150
+ end
151
+ alias :record :record_macro
152
+ end
153
+ end
@@ -0,0 +1,3 @@
1
+ require 'invocation'
2
+
3
+ require 'record_invocation/record_invocation'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evt-record_invocation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - The Eventide Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-07-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: evt-invocation
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test_bench
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: " "
42
+ email: opensource@eventide-project.org
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/record_invocation.rb
48
+ - lib/record_invocation/controls.rb
49
+ - lib/record_invocation/controls/invocation.rb
50
+ - lib/record_invocation/controls/recorder.rb
51
+ - lib/record_invocation/record_invocation.rb
52
+ homepage: https://github.com/eventide-project/record-invocation
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '2.4'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.4.6
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Record method invocations, query method invocations, and use predicates to
75
+ verify a method's invocation
76
+ test_files: []