naught 2.1.0 → 2.2.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/lib/naught/version.rb +1 -1
- data/sig/naught.rbs +286 -0
- metadata +4 -31
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 42abb6770fb263920abd64584a31c5e3eab901bcf25efa610d538e1886db5980
|
|
4
|
+
data.tar.gz: 2e914d3fc95bb6dcb99a7925f09d1ef747165175cee34959f6491d06c71480e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6c803b6f0fc83d81fa34f65b87ebaabfb10b385e3891038f0fb7a39540cd6df934bc833a84bce59cb0d84b98f53724dcb1ca6453edbcd2b538d23a8f56655dc0
|
|
7
|
+
data.tar.gz: 20f98f1702229f16cbc98385f0432b3c5516940afe37684cf8e14a63a2d427c464989ca8de36f389ae7e30a891df2362d3e01447b021947047c74d6af280fa19
|
data/lib/naught/version.rb
CHANGED
data/sig/naught.rbs
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# Type signature for Naught - a toolkit for building Null Objects in Ruby
|
|
2
|
+
|
|
3
|
+
module Naught
|
|
4
|
+
VERSION: String
|
|
5
|
+
|
|
6
|
+
# Lightweight proxy for tracking chained method calls
|
|
7
|
+
class ChainProxy < BasicObject
|
|
8
|
+
def initialize: (untyped root, Array[CallLocation] current_trace) -> void
|
|
9
|
+
def method_missing: (Symbol method_name, *untyped args) ?{ () -> untyped } -> ChainProxy
|
|
10
|
+
def respond_to?: (*untyped, **untyped) -> true
|
|
11
|
+
def inspect: () -> String
|
|
12
|
+
def class: () -> Class
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Utility for parsing Ruby caller/backtrace information
|
|
16
|
+
module CallerInfo
|
|
17
|
+
# module_function methods are both instance and singleton methods
|
|
18
|
+
def self?.parse: (String caller_string) -> { path: String?, lineno: Integer, base_label: String? }
|
|
19
|
+
def self?.extract_base_label: (String? method_part) -> String?
|
|
20
|
+
def self?.extract_signature: (String? method_part) -> String?
|
|
21
|
+
def self?.split_signature: (String signature) -> Array[String?]
|
|
22
|
+
def self?.format_caller_for_pebble: (Array[String] stack) -> String?
|
|
23
|
+
def self?.count_block_levels: (Array[String] stack, String target_method) -> Integer
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def self?.parse_signature: (String signature) -> Array[String?]
|
|
28
|
+
def self?.adjusted_block_info: (String? block_info, Array[String] stack, String method_name) -> String?
|
|
29
|
+
def self?.simple_block?: (String? block_info) -> bool
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Represents a single method call in a null object's call trace
|
|
33
|
+
class CallLocation
|
|
34
|
+
def self.from_caller: (Symbol | String method_name, Array[untyped] args, String? caller_string) -> CallLocation
|
|
35
|
+
|
|
36
|
+
attr_reader label: String
|
|
37
|
+
attr_reader args: Array[untyped]
|
|
38
|
+
attr_reader path: String
|
|
39
|
+
attr_reader lineno: Integer
|
|
40
|
+
attr_reader base_label: String?
|
|
41
|
+
|
|
42
|
+
def absolute_path: () -> String
|
|
43
|
+
|
|
44
|
+
def initialize: (label: Symbol | String, args: Array[untyped], path: String, lineno: Integer, ?base_label: String?) -> void
|
|
45
|
+
def to_s: () -> String
|
|
46
|
+
def inspect: () -> String
|
|
47
|
+
def ==: (untyped other) -> bool
|
|
48
|
+
def eql?: (untyped other) -> bool
|
|
49
|
+
def hash: () -> Integer
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Build a null object class using the builder DSL
|
|
53
|
+
def self.build: () { (NullClassBuilder) -> void } -> Class
|
|
54
|
+
| () -> Class
|
|
55
|
+
|
|
56
|
+
# Marker module mixed into generated null objects
|
|
57
|
+
module NullObjectTag
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Marker module for null-safe proxy wrappers
|
|
61
|
+
module NullSafeProxyTag
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# BasicObject subclass used as a minimal base for null objects
|
|
65
|
+
class BasicObject < ::BasicObject
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Helper conversion API available on generated null classes
|
|
69
|
+
module Conversions
|
|
70
|
+
# Configure a Conversions module for a specific null class
|
|
71
|
+
def self.configure: (Module mod, null_class: Class, null_equivs: Array[untyped]) -> void
|
|
72
|
+
|
|
73
|
+
# Return a null object for object if it is null-equivalent
|
|
74
|
+
def Null: (?untyped object) -> untyped
|
|
75
|
+
|
|
76
|
+
# Return a null object for null-equivalent values, otherwise the value
|
|
77
|
+
def Maybe: (?untyped object) -> untyped
|
|
78
|
+
| [T] () { () -> T } -> (T | untyped)
|
|
79
|
+
|
|
80
|
+
# Return the value if not null-equivalent, otherwise raise
|
|
81
|
+
def Just: (?untyped object) -> untyped
|
|
82
|
+
| [T] () { () -> T } -> T
|
|
83
|
+
|
|
84
|
+
# Return nil for null objects, otherwise return the value
|
|
85
|
+
def Actual: (?untyped object) -> untyped
|
|
86
|
+
| [T] () { () -> T } -> T?
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def __null_class__: () -> Class
|
|
91
|
+
def __null_equivs__: () -> Array[untyped]
|
|
92
|
+
def null_object?: (untyped object) -> bool
|
|
93
|
+
def null_equivalent?: (untyped object, ?include_nothing: bool) -> bool
|
|
94
|
+
def make_null: (Integer caller_offset) -> untyped
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Strategies for stubbing methods on null objects
|
|
98
|
+
module StubStrategy
|
|
99
|
+
# Stub that returns nil from any method
|
|
100
|
+
module ReturnNil
|
|
101
|
+
def self.apply: (Module subject, Symbol name) -> void
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Stub that returns self from any method (black hole)
|
|
105
|
+
module ReturnSelf
|
|
106
|
+
def self.apply: (Module subject, Symbol name) -> void
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Builds customized null object classes via a small DSL
|
|
111
|
+
class NullClassBuilder
|
|
112
|
+
# Namespace for builder command classes
|
|
113
|
+
module Commands
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
type stub_strategy = singleton(StubStrategy::ReturnNil) | singleton(StubStrategy::ReturnSelf)
|
|
117
|
+
type deferred_operation = ^(untyped) -> void
|
|
118
|
+
|
|
119
|
+
attr_accessor base_class: Class
|
|
120
|
+
attr_accessor inspect_proc: ^() -> String
|
|
121
|
+
attr_accessor interface_defined: bool
|
|
122
|
+
|
|
123
|
+
def interface_defined?: () -> bool
|
|
124
|
+
|
|
125
|
+
def initialize: () -> void
|
|
126
|
+
|
|
127
|
+
# Apply a customization block to this builder
|
|
128
|
+
def customize: () { (NullClassBuilder) -> void } -> void
|
|
129
|
+
| () -> void
|
|
130
|
+
|
|
131
|
+
# Module that holds customization methods
|
|
132
|
+
def customization_module: () -> Module
|
|
133
|
+
|
|
134
|
+
# Values treated as null-equivalent
|
|
135
|
+
def null_equivalents: () -> Array[untyped]
|
|
136
|
+
|
|
137
|
+
# Generate the null object class based on queued operations
|
|
138
|
+
def generate_class: () -> Class
|
|
139
|
+
|
|
140
|
+
# Configure method stubs to return self (black hole behavior)
|
|
141
|
+
def black_hole: () -> void
|
|
142
|
+
|
|
143
|
+
# Make null objects respond to any message and stub method_missing
|
|
144
|
+
def respond_to_any_message: () -> void
|
|
145
|
+
|
|
146
|
+
# Queue a deferred operation to be applied during class generation
|
|
147
|
+
# Block is evaluated in module context via module_eval
|
|
148
|
+
def defer: (?Hash[Symbol, bool] options) { (untyped) -> untyped } -> void
|
|
149
|
+
|
|
150
|
+
# Prepend a module generated from the given block
|
|
151
|
+
# Block is evaluated in module context via Module.new
|
|
152
|
+
def defer_prepend_module: () { () -> untyped } -> void
|
|
153
|
+
|
|
154
|
+
# Stub a method using the current stub strategy
|
|
155
|
+
def stub_method: (untyped subject, Symbol name) -> void
|
|
156
|
+
|
|
157
|
+
private
|
|
158
|
+
|
|
159
|
+
def build_null_class: (Module generation_mod) -> Class
|
|
160
|
+
def define_basic_methods: () -> void
|
|
161
|
+
def apply_operations: (Array[deferred_operation] operations, untyped module_or_class) -> void
|
|
162
|
+
def define_basic_instance_methods: () -> void
|
|
163
|
+
def define_basic_class_methods: () -> void
|
|
164
|
+
def class_operations: () -> Array[deferred_operation]
|
|
165
|
+
def operations: () -> Array[deferred_operation]
|
|
166
|
+
def prepend_modules: () -> Array[Module]
|
|
167
|
+
def lookup_command: (Symbol method_name) -> singleton(Command)?
|
|
168
|
+
def camelize: (Symbol | String name) -> String
|
|
169
|
+
|
|
170
|
+
# Base class for builder command implementations
|
|
171
|
+
class Command
|
|
172
|
+
attr_reader builder: NullClassBuilder
|
|
173
|
+
|
|
174
|
+
def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
|
|
175
|
+
def call: () -> void
|
|
176
|
+
|
|
177
|
+
private
|
|
178
|
+
|
|
179
|
+
def defer: (?Hash[Symbol, bool] options) { (untyped) -> untyped } -> void
|
|
180
|
+
def defer_class: () { (untyped) -> untyped } -> void
|
|
181
|
+
def defer_prepend_module: () { () -> untyped } -> void
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Command classes under the Commands namespace
|
|
187
|
+
module Naught
|
|
188
|
+
class NullClassBuilder
|
|
189
|
+
module Commands
|
|
190
|
+
class DefineExplicitConversions < Naught::NullClassBuilder::Command
|
|
191
|
+
def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
|
|
192
|
+
def call: () -> void
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
class DefineImplicitConversions < Naught::NullClassBuilder::Command
|
|
196
|
+
EMPTY_ARRAY: Array[untyped]
|
|
197
|
+
EMPTY_HASH: Hash[untyped, untyped]
|
|
198
|
+
RETURN_VALUES: Hash[Symbol, untyped]
|
|
199
|
+
|
|
200
|
+
def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
|
|
201
|
+
def call: () -> void
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
class Mimic < Naught::NullClassBuilder::Command
|
|
205
|
+
METHODS_TO_SKIP: Array[Symbol]
|
|
206
|
+
NULL_SINGLETON_CLASS: Class
|
|
207
|
+
|
|
208
|
+
attr_reader class_to_mimic: Class
|
|
209
|
+
attr_reader include_super: bool
|
|
210
|
+
attr_reader singleton_class: Class
|
|
211
|
+
attr_reader example_instance: untyped
|
|
212
|
+
attr_reader include_dynamic: bool
|
|
213
|
+
|
|
214
|
+
def initialize: (NullClassBuilder builder, Class | Hash[Symbol, untyped] class_to_mimic_or_options, ?Hash[Symbol, untyped] options) ?{ () -> untyped } -> void
|
|
215
|
+
def call: () -> void
|
|
216
|
+
|
|
217
|
+
private
|
|
218
|
+
|
|
219
|
+
def parse_arguments: (Class | Hash[Symbol, untyped] class_to_mimic_or_options, Hash[Symbol, untyped] options) -> void
|
|
220
|
+
def configure_builder: () -> void
|
|
221
|
+
def root_class_of: (Class klass) -> Class
|
|
222
|
+
def methods_to_stub: () -> Array[Symbol]
|
|
223
|
+
def dynamic_methods: () -> Array[Symbol]
|
|
224
|
+
def discover_method_candidates: () -> Array[Symbol]
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
class Impersonate < Naught::NullClassBuilder::Commands::Mimic
|
|
228
|
+
def initialize: (NullClassBuilder builder, Class class_to_impersonate, ?Hash[Symbol, untyped] options) ?{ () -> untyped } -> void
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
class Pebble < Naught::NullClassBuilder::Command
|
|
232
|
+
interface _Output
|
|
233
|
+
def puts: (String) -> void
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
@output: _Output
|
|
237
|
+
|
|
238
|
+
def initialize: (NullClassBuilder builder, ?_Output output) ?{ () -> untyped } -> void
|
|
239
|
+
def call: () -> void
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
class PredicatesReturn < Naught::NullClassBuilder::Command
|
|
243
|
+
@return_value: untyped
|
|
244
|
+
|
|
245
|
+
def initialize: (NullClassBuilder builder, untyped return_value) ?{ () -> untyped } -> void
|
|
246
|
+
def call: () -> void
|
|
247
|
+
|
|
248
|
+
private
|
|
249
|
+
|
|
250
|
+
def install_method_missing_override: () -> void
|
|
251
|
+
def install_predicate_method_overrides: () -> void
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
class Singleton < Naught::NullClassBuilder::Command
|
|
255
|
+
def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
|
|
256
|
+
def call: () -> void
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
class Traceable < Naught::NullClassBuilder::Command
|
|
260
|
+
def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
|
|
261
|
+
def call: () -> void
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
class NullSafeProxy < Naught::NullClassBuilder::Command
|
|
265
|
+
def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
|
|
266
|
+
def call: () -> void
|
|
267
|
+
|
|
268
|
+
private
|
|
269
|
+
|
|
270
|
+
def build_proxy_class: (Class null_class, Array[untyped] null_equivs) -> Class
|
|
271
|
+
def install_null_safe_conversion: (Class null_class, Class proxy_class, Array[untyped] null_equivs) -> void
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
class Callstack < Naught::NullClassBuilder::Command
|
|
275
|
+
def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
|
|
276
|
+
def call: () -> void
|
|
277
|
+
|
|
278
|
+
private
|
|
279
|
+
|
|
280
|
+
def install_call_trace_accessor: () -> void
|
|
281
|
+
def install_method_missing_tracking: () -> void
|
|
282
|
+
def install_chain_proxy_class: () -> void
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
metadata
CHANGED
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: naught
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Avdi Grimm
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
name: bundler
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - ">="
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '2.0'
|
|
19
|
-
type: :development
|
|
20
|
-
prerelease: false
|
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
-
requirements:
|
|
23
|
-
- - ">="
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
25
|
-
version: '2.0'
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: rake
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '12.0'
|
|
33
|
-
type: :development
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '12.0'
|
|
11
|
+
dependencies: []
|
|
40
12
|
description: Naught is a toolkit for building Null Objects
|
|
41
13
|
email:
|
|
42
14
|
- avdi@avdi.org
|
|
@@ -66,6 +38,7 @@ files:
|
|
|
66
38
|
- lib/naught/null_class_builder/commands/traceable.rb
|
|
67
39
|
- lib/naught/stub_strategy.rb
|
|
68
40
|
- lib/naught/version.rb
|
|
41
|
+
- sig/naught.rbs
|
|
69
42
|
homepage: https://github.com/avdi/naught
|
|
70
43
|
licenses:
|
|
71
44
|
- MIT
|
|
@@ -88,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
88
61
|
- !ruby/object:Gem::Version
|
|
89
62
|
version: '0'
|
|
90
63
|
requirements: []
|
|
91
|
-
rubygems_version: 4.0.
|
|
64
|
+
rubygems_version: 4.0.7
|
|
92
65
|
specification_version: 4
|
|
93
66
|
summary: Naught is a toolkit for building Null Objects
|
|
94
67
|
test_files: []
|