naught 2.1.0 → 2.3.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/naught/version.rb +1 -1
  3. data/sig/naught.rbs +299 -0
  4. metadata +4 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e4aa0e2eddca2722a669cb141655ed975ad91535158d9d0cb09566f6971de8f
4
- data.tar.gz: 2872a770d1b8d58336cee9b29be4b6108511893615c1e2c621ac2e9f8a321e56
3
+ metadata.gz: 7695d34e478428fe2a3dbb3164159c3ad5cbf9acea047fa38cdf8067e40edbe6
4
+ data.tar.gz: fe8fd997afe43bb28ddb77f926d8c5d27ab916ab74260214551b2bf0f7744da9
5
5
  SHA512:
6
- metadata.gz: c2cf48a809f2777cb2a39c598aac6643bc765b44d39e29c6dbf8c539a394f134f27cced5517f84ca4e7590ec43e0ee01f9b896987c5c48a5b8d08c4793128fad
7
- data.tar.gz: 8eaa91494482d1a081c1fa6c95b4c54d6e2f5cf6d1cc424bcf86cfd9a09c65618ba5fb46ca7151d2c6d288806aadc578116b97bf85c6f4df14211bf20ce0c5d0
6
+ metadata.gz: cb254309968a424a1e41a8c477cfd580958f3200b352fa86db071707c8df63c712a14eb276b60dd75f346bdf7ccd884c6fd963c5a74a41c1fd683312c382f2fa
7
+ data.tar.gz: 82a275df524b7984d23a3bd8d87c3660d96abe4ff710d6635566a9f2b7d7c2a07bff999da06349dc9c1cafc8864c9efd9e12fbdf59e7c6b59a81e80587d4326f
@@ -1,5 +1,5 @@
1
1
  # Top-level namespace for Naught
2
2
  module Naught
3
3
  # Gem version
4
- VERSION = "2.1.0"
4
+ VERSION = "2.3.0"
5
5
  end
data/sig/naught.rbs ADDED
@@ -0,0 +1,299 @@
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
+ # DSL methods dispatched via method_missing to command classes
144
+ def define_explicit_conversions: () -> void
145
+ def define_implicit_conversions: () -> void
146
+ def predicates_return: (untyped value) -> void
147
+ def mimic: (Class class_to_mimic, ?{ ?include_super: bool, ?include_dynamic: bool } options) -> void
148
+ | ({ example: untyped, ?include_super: bool, ?include_dynamic: bool } options) -> void
149
+ def impersonate: (Class class_to_impersonate, ?{ ?include_super: bool, ?include_dynamic: bool } options) -> void
150
+ def pebble: (?Naught::NullClassBuilder::Commands::Pebble::_Output output) -> void
151
+ def singleton: () -> void
152
+ def traceable: () -> void
153
+ def callstack: () -> void
154
+ def null_safe_proxy: () -> void
155
+
156
+ # Make null objects respond to any message and stub method_missing
157
+ def respond_to_any_message: () -> void
158
+
159
+ # Queue a deferred operation to be applied during class generation
160
+ # Block is evaluated in module context via module_eval
161
+ def defer: (?Hash[Symbol, bool] options) { (untyped) -> untyped } -> void
162
+
163
+ # Prepend a module generated from the given block
164
+ # Block is evaluated in module context via Module.new
165
+ def defer_prepend_module: () { () -> untyped } -> void
166
+
167
+ # Stub a method using the current stub strategy
168
+ def stub_method: (untyped subject, Symbol name) -> void
169
+
170
+ private
171
+
172
+ def build_null_class: (Module generation_mod) -> Class
173
+ def define_basic_methods: () -> void
174
+ def apply_operations: (Array[deferred_operation] operations, untyped module_or_class) -> void
175
+ def define_basic_instance_methods: () -> void
176
+ def define_basic_class_methods: () -> void
177
+ def class_operations: () -> Array[deferred_operation]
178
+ def operations: () -> Array[deferred_operation]
179
+ def prepend_modules: () -> Array[Module]
180
+ def lookup_command: (Symbol method_name) -> singleton(Command)?
181
+ def camelize: (Symbol | String name) -> String
182
+
183
+ # Base class for builder command implementations
184
+ class Command
185
+ attr_reader builder: NullClassBuilder
186
+
187
+ def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
188
+ def call: () -> void
189
+
190
+ private
191
+
192
+ def defer: (?Hash[Symbol, bool] options) { (untyped) -> untyped } -> void
193
+ def defer_class: () { (untyped) -> untyped } -> void
194
+ def defer_prepend_module: () { () -> untyped } -> void
195
+ end
196
+ end
197
+ end
198
+
199
+ # Command classes under the Commands namespace
200
+ module Naught
201
+ class NullClassBuilder
202
+ module Commands
203
+ class DefineExplicitConversions < Naught::NullClassBuilder::Command
204
+ def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
205
+ def call: () -> void
206
+ end
207
+
208
+ class DefineImplicitConversions < Naught::NullClassBuilder::Command
209
+ EMPTY_ARRAY: Array[untyped]
210
+ EMPTY_HASH: Hash[untyped, untyped]
211
+ RETURN_VALUES: Hash[Symbol, untyped]
212
+
213
+ def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
214
+ def call: () -> void
215
+ end
216
+
217
+ class Mimic < Naught::NullClassBuilder::Command
218
+ METHODS_TO_SKIP: Array[Symbol]
219
+ NULL_SINGLETON_CLASS: Class
220
+
221
+ attr_reader class_to_mimic: Class
222
+ attr_reader include_super: bool
223
+ attr_reader singleton_class: Class
224
+ attr_reader example_instance: untyped
225
+ attr_reader include_dynamic: bool
226
+
227
+ def initialize: (NullClassBuilder builder, Class | Hash[Symbol, untyped] class_to_mimic_or_options, ?Hash[Symbol, untyped] options) ?{ () -> untyped } -> void
228
+ def call: () -> void
229
+
230
+ private
231
+
232
+ def parse_arguments: (Class | Hash[Symbol, untyped] class_to_mimic_or_options, Hash[Symbol, untyped] options) -> void
233
+ def configure_builder: () -> void
234
+ def root_class_of: (Class klass) -> Class
235
+ def methods_to_stub: () -> Array[Symbol]
236
+ def dynamic_methods: () -> Array[Symbol]
237
+ def discover_method_candidates: () -> Array[Symbol]
238
+ end
239
+
240
+ class Impersonate < Naught::NullClassBuilder::Commands::Mimic
241
+ def initialize: (NullClassBuilder builder, Class class_to_impersonate, ?Hash[Symbol, untyped] options) ?{ () -> untyped } -> void
242
+ end
243
+
244
+ class Pebble < Naught::NullClassBuilder::Command
245
+ interface _Output
246
+ def puts: (String) -> void
247
+ end
248
+
249
+ @output: _Output
250
+
251
+ def initialize: (NullClassBuilder builder, ?_Output output) ?{ () -> untyped } -> void
252
+ def call: () -> void
253
+ end
254
+
255
+ class PredicatesReturn < Naught::NullClassBuilder::Command
256
+ @return_value: untyped
257
+
258
+ def initialize: (NullClassBuilder builder, untyped return_value) ?{ () -> untyped } -> void
259
+ def call: () -> void
260
+
261
+ private
262
+
263
+ def install_method_missing_override: () -> void
264
+ def install_predicate_method_overrides: () -> void
265
+ end
266
+
267
+ class Singleton < Naught::NullClassBuilder::Command
268
+ def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
269
+ def call: () -> void
270
+ end
271
+
272
+ class Traceable < Naught::NullClassBuilder::Command
273
+ def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
274
+ def call: () -> void
275
+ end
276
+
277
+ class NullSafeProxy < Naught::NullClassBuilder::Command
278
+ def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
279
+ def call: () -> void
280
+
281
+ private
282
+
283
+ def build_proxy_class: (Class null_class, Array[untyped] null_equivs) -> Class
284
+ def install_null_safe_conversion: (Class null_class, Class proxy_class, Array[untyped] null_equivs) -> void
285
+ end
286
+
287
+ class Callstack < Naught::NullClassBuilder::Command
288
+ def initialize: (NullClassBuilder builder, *untyped, **untyped) ?{ () -> untyped } -> void
289
+ def call: () -> void
290
+
291
+ private
292
+
293
+ def install_call_trace_accessor: () -> void
294
+ def install_method_missing_tracking: () -> void
295
+ def install_chain_proxy_class: () -> void
296
+ end
297
+ end
298
+ end
299
+ 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.1.0
4
+ version: 2.3.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.6
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: []