core-inspect 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -10
- data/lib/core/inspect/version.rb +1 -1
- data/lib/core/inspect.rb +110 -2
- metadata +12 -13
- data/lib/is/inspectable.rb +0 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d7b6c077a16af15bd8d6ffe2905d1bb2854e8338f03fc244592f3d4f8245b89
|
4
|
+
data.tar.gz: cdf2f0b1e1168c3d4b15efdbb2692b6faa2d7e6d37686935e7d1ecd306545019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 959c6142dc9b0e42d896dfd8df539cdaccd717246ae7aeadd17fc7ebe1d011fdd8fdea00615b8f73ddf90fb760e59d140357ecdc5859c374d9efdd66e5b27dfd
|
7
|
+
data.tar.gz: 647dc9cb901ddf6e277f1eb2256b7319c36b874f4f8a7a68bcf4076152590d1ea35fb143858fa495f1a5c49da6e1f0cb31e0ad924b51f725d42e7687fb22bb7c
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,34 @@
|
|
1
|
-
## [v0.
|
1
|
+
## [v0.2.0](https://github.com/bryanp/corerb/releases/tag/2023-12-24)
|
2
|
+
|
3
|
+
*released on 2023-12-24*
|
4
|
+
|
5
|
+
* `dep` [#143](https://github.com/bryanp/corerb/pull/143) Deprecate `Is::*` and `Refine::*` namespaces ([bryanp](https://github.com/bryanp))
|
6
|
+
* `dep` [#135](https://github.com/bryanp/corerb/pull/135) Remove Ruby 2 support ([bryanp](https://github.com/bryanp))
|
7
|
+
|
8
|
+
## [v0.1.1](https://github.com/bryanp/corerb/releases/tag/2022-01-13)
|
2
9
|
|
3
10
|
*released on 2022-01-13*
|
4
11
|
|
5
|
-
* `fix` [#119](https://github.com/
|
12
|
+
* `fix` [#119](https://github.com/bryanp/corerb/pull/119) Access inspectable state through instance variables ([bryanp](https://github.com/bryanp))
|
6
13
|
|
7
|
-
## [v0.1.0](https://github.com/
|
14
|
+
## [v0.1.0](https://github.com/bryanp/corerb/releases/tag/2021-11-23.1)
|
8
15
|
|
9
16
|
*released on 2021-11-23*
|
10
17
|
|
11
|
-
* `add` [#110](https://github.com/
|
12
|
-
* `chg` [#109](https://github.com/
|
18
|
+
* `add` [#110](https://github.com/bryanp/corerb/pull/110) Introduce Core::Inspect::Inspectable for greater customization ([bryanp](https://github.com/bryanp))
|
19
|
+
* `chg` [#109](https://github.com/bryanp/corerb/pull/109) Prefer `__send__` to `send` ([bryanp](https://github.com/bryanp))
|
13
20
|
|
14
|
-
## [v0.0.2](https://github.com/
|
21
|
+
## [v0.0.2](https://github.com/bryanp/corerb/releases/tag/2021-11-02)
|
15
22
|
|
16
23
|
*released on 2021-11-02*
|
17
24
|
|
18
|
-
* `chg` [#97](https://github.com/
|
25
|
+
* `chg` [#97](https://github.com/bryanp/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
|
19
26
|
|
20
|
-
## [v0.0.0](https://github.com/
|
27
|
+
## [v0.0.0](https://github.com/bryanp/corerb/releases/tag/2021-07-07)
|
21
28
|
|
22
29
|
*released on 2021-07-07*
|
23
30
|
|
24
|
-
* `chg` [#42](https://github.com/
|
25
|
-
* `add` [#34](https://github.com/
|
31
|
+
* `chg` [#42](https://github.com/bryanp/corerb/pull/42) Drop Ruby 2.6 support from core-inspect ([bryanp](https://github.com/bryanp))
|
32
|
+
* `add` [#34](https://github.com/bryanp/corerb/pull/34) Initial implementation of core-inspect ([bryanp](https://github.com/bryanp))
|
26
33
|
|
27
34
|
|
data/lib/core/inspect/version.rb
CHANGED
data/lib/core/inspect.rb
CHANGED
@@ -1,10 +1,118 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "core/extension"
|
4
|
+
require "core/local"
|
5
|
+
require "core/state"
|
6
|
+
|
3
7
|
module Core
|
8
|
+
# [public] Customized inspections for any object.
|
9
|
+
#
|
4
10
|
module Inspect
|
5
11
|
require_relative "inspect/inspection"
|
6
12
|
require_relative "inspect/version"
|
13
|
+
|
14
|
+
extend Core::Extension
|
15
|
+
|
16
|
+
extends dependencies: [Core::State]
|
17
|
+
|
18
|
+
extends :definition do
|
19
|
+
# [public] Sets one or more instance variables or instance methods as inspectable.
|
20
|
+
#
|
21
|
+
# without - An array of instance variables or instance methods that should not be inspected.
|
22
|
+
#
|
23
|
+
def inspects(*inspectables, without: [])
|
24
|
+
if inspectables.any?
|
25
|
+
mutate_state :__inspectables__ do |current_inspectables|
|
26
|
+
inspectables.each do |inspectable|
|
27
|
+
inspection = build_inspection(inspectable)
|
28
|
+
current_inspectables[inspection.name] = inspection
|
29
|
+
end
|
30
|
+
|
31
|
+
current_inspectables
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if without.any?
|
36
|
+
mutate_state :__uninspectables__ do |current_uninspectables|
|
37
|
+
without.each do |inspectable|
|
38
|
+
inspection = build_inspection(inspectable)
|
39
|
+
current_uninspectables[inspection.name] = inspection
|
40
|
+
end
|
41
|
+
|
42
|
+
current_uninspectables
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private def build_inspection(inspectable)
|
48
|
+
case inspectable
|
49
|
+
when Core::Inspect::Inspection
|
50
|
+
inspectable
|
51
|
+
else
|
52
|
+
Core::Inspect::Inspection.new(name: inspectable)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
applies do
|
58
|
+
state :__inspectables__, default: {}
|
59
|
+
state :__uninspectables__, default: {}
|
60
|
+
end
|
61
|
+
|
62
|
+
# [public] Inspects the object.
|
63
|
+
#
|
64
|
+
def inspect
|
65
|
+
inspection = +"#<#{self.class}:0x#{__id__.to_s(16)}"
|
66
|
+
|
67
|
+
if Inspect.inspecting?(self)
|
68
|
+
"#{inspection} ...>"
|
69
|
+
else
|
70
|
+
Inspect.prevent_recursion(self) do
|
71
|
+
each_inspectable do |inspectable|
|
72
|
+
inspection << ", #{inspectable.name}=#{inspectable.resolve(self).inspect}"
|
73
|
+
end
|
74
|
+
|
75
|
+
inspection.strip << ">"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private def each_inspectable
|
81
|
+
inspectables = if @__inspectables__.any?
|
82
|
+
@__inspectables__
|
83
|
+
else
|
84
|
+
instance_variables.map(&:to_s).reject { |instance_variable|
|
85
|
+
instance_variable.start_with?("@_")
|
86
|
+
}.each_with_object({}) { |instance_variable, hash|
|
87
|
+
hash[instance_variable] = self.class.__send__(:build_inspection, instance_variable)
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
inspectables.each_value do |inspectable|
|
92
|
+
unless @__uninspectables__.include?(inspectable.name)
|
93
|
+
yield inspectable
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class << self
|
99
|
+
include Core::Local
|
100
|
+
|
101
|
+
def prevent_recursion(object)
|
102
|
+
object_id = object.object_id
|
103
|
+
inspected_objects[object_id] = true
|
104
|
+
yield
|
105
|
+
ensure
|
106
|
+
inspected_objects.delete(object_id)
|
107
|
+
end
|
108
|
+
|
109
|
+
def inspecting?(object)
|
110
|
+
inspected_objects[object.object_id]
|
111
|
+
end
|
112
|
+
|
113
|
+
def inspected_objects
|
114
|
+
localized(:__corerb_inspected_objects__) || localize(:__corerb_inspected_objects__, {})
|
115
|
+
end
|
116
|
+
end
|
7
117
|
end
|
8
118
|
end
|
9
|
-
|
10
|
-
require_relative "../is/inspectable"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: core-inspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: core-extension
|
@@ -16,44 +16,44 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: core-local
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: core-state
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.2'
|
55
55
|
description: Customized inspections for any object.
|
56
|
-
email: bryan@
|
56
|
+
email: bryan@bryanp.org
|
57
57
|
executables: []
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
@@ -63,8 +63,7 @@ files:
|
|
63
63
|
- lib/core/inspect.rb
|
64
64
|
- lib/core/inspect/inspection.rb
|
65
65
|
- lib/core/inspect/version.rb
|
66
|
-
|
67
|
-
homepage: https://github.com/metabahn/corerb/
|
66
|
+
homepage: https://github.com/bryanp/corerb/
|
68
67
|
licenses:
|
69
68
|
- MPL-2.0
|
70
69
|
metadata: {}
|
@@ -76,14 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
75
|
requirements:
|
77
76
|
- - ">="
|
78
77
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
78
|
+
version: '3.0'
|
80
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
80
|
requirements:
|
82
81
|
- - ">="
|
83
82
|
- !ruby/object:Gem::Version
|
84
83
|
version: '0'
|
85
84
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.5.1
|
87
86
|
signing_key:
|
88
87
|
specification_version: 4
|
89
88
|
summary: Customized inspections for any object.
|
data/lib/is/inspectable.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "is/extension"
|
4
|
-
require "is/localized"
|
5
|
-
require "is/stateful"
|
6
|
-
|
7
|
-
require_relative "../core/inspect/inspection"
|
8
|
-
|
9
|
-
module Is
|
10
|
-
# [public] Customized inspections for any object.
|
11
|
-
#
|
12
|
-
module Inspectable
|
13
|
-
extend Is::Extension
|
14
|
-
|
15
|
-
extends dependencies: [Is::Stateful]
|
16
|
-
|
17
|
-
extends :definition do
|
18
|
-
# [public] Sets one or more instance variables or instance methods as inspectable.
|
19
|
-
#
|
20
|
-
# without - An array of instance variables or instance methods that should not be inspected.
|
21
|
-
#
|
22
|
-
def inspects(*inspectables, without: [])
|
23
|
-
if inspectables.any?
|
24
|
-
mutate_state :__inspectables__ do |current_inspectables|
|
25
|
-
inspectables.each do |inspectable|
|
26
|
-
inspection = build_inspection(inspectable)
|
27
|
-
current_inspectables[inspection.name] = inspection
|
28
|
-
end
|
29
|
-
|
30
|
-
current_inspectables
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
if without.any?
|
35
|
-
mutate_state :__uninspectables__ do |current_uninspectables|
|
36
|
-
without.each do |inspectable|
|
37
|
-
inspection = build_inspection(inspectable)
|
38
|
-
current_uninspectables[inspection.name] = inspection
|
39
|
-
end
|
40
|
-
|
41
|
-
current_uninspectables
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private def build_inspection(inspectable)
|
47
|
-
case inspectable
|
48
|
-
when Core::Inspect::Inspection
|
49
|
-
inspectable
|
50
|
-
else
|
51
|
-
Core::Inspect::Inspection.new(name: inspectable)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
applies do
|
57
|
-
state :__inspectables__, default: {}
|
58
|
-
state :__uninspectables__, default: {}
|
59
|
-
end
|
60
|
-
|
61
|
-
# [public] Inspects the object.
|
62
|
-
#
|
63
|
-
def inspect
|
64
|
-
inspection = +"#<#{self.class}:0x#{__id__.to_s(16)}"
|
65
|
-
|
66
|
-
if Inspectable.inspecting?(self)
|
67
|
-
"#{inspection} ...>"
|
68
|
-
else
|
69
|
-
Inspectable.prevent_recursion(self) do
|
70
|
-
each_inspectable do |inspectable|
|
71
|
-
inspection << ", #{inspectable.name}=#{inspectable.resolve(self).inspect}"
|
72
|
-
end
|
73
|
-
|
74
|
-
inspection.strip << ">"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
private def each_inspectable
|
80
|
-
inspectables = if @__inspectables__.any?
|
81
|
-
@__inspectables__
|
82
|
-
else
|
83
|
-
instance_variables.map(&:to_s).reject { |instance_variable|
|
84
|
-
instance_variable.start_with?("@_")
|
85
|
-
}.each_with_object({}) { |instance_variable, hash|
|
86
|
-
hash[instance_variable] = self.class.__send__(:build_inspection, instance_variable)
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
inspectables.each_value do |inspectable|
|
91
|
-
unless @__uninspectables__.include?(inspectable.name)
|
92
|
-
yield inspectable
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
class << self
|
98
|
-
include Is::Localized
|
99
|
-
|
100
|
-
def prevent_recursion(object)
|
101
|
-
object_id = object.object_id
|
102
|
-
inspected_objects[object_id] = true
|
103
|
-
yield
|
104
|
-
ensure
|
105
|
-
inspected_objects.delete(object_id)
|
106
|
-
end
|
107
|
-
|
108
|
-
def inspecting?(object)
|
109
|
-
inspected_objects[object.object_id]
|
110
|
-
end
|
111
|
-
|
112
|
-
def inspected_objects
|
113
|
-
localized(:__corerb_inspected_objects__) || localize(:__corerb_inspected_objects__, {})
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|