core-inspect 0.0.0 → 0.1.1

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: c1a924e979010d66467111a26506ef52ddc802e0bf12f077174d222f042e115f
4
- data.tar.gz: 7766031c888ec93a6bb19cbaa06bd6550095c068a198a4ace6b8868c3ab369c9
3
+ metadata.gz: 8f07082e1925de58943a99e20889e090550e5efcdd08932a726a087f2bb490b9
4
+ data.tar.gz: 3ec5210448d211c6393df04cae72505a8dc6065a87e91e02e908a7b0358f5da4
5
5
  SHA512:
6
- metadata.gz: dd7410cdb890526afe8e7683be091f431dcaf0f9ca5699a1b9a4ee70704a94752c5efc412516c8ceff41a71c3ae1a80962f2fc024b879e502b925242c0af3449
7
- data.tar.gz: 5a4eede2a998b7037b785d87e94278f292f9941a345a81b7fdf1172c1453a92874fd97f917f413383491dc6419be48e6a72353b040bbd267db7f2102674e9cb7
6
+ metadata.gz: c814fedceb04f969459aeb57f7db02e2b217851238138379c32daefb34445d6b155b9fc583709c7cfc26f2e1c218a8f85b6f49b07c0db3407e0cd49a93178a18
7
+ data.tar.gz: a4fa78503a24febdc58d7e679fe71944a618c8f2f8a52b1fc1eb63361cd9f4c37deeacf838a92371217cb0c99a81763d8d9897fb7f9cf13cfea94753b606a603
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [v0.1.1](https://github.com/metabahn/corerb/releases/tag/2022-01-13)
2
+
3
+ *released on 2022-01-13*
4
+
5
+ * `fix` [#119](https://github.com/metabahn/corerb/pull/119) Access inspectable state through instance variables ([bryanp](https://github.com/bryanp))
6
+
7
+ ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-11-23.1)
8
+
9
+ *released on 2021-11-23*
10
+
11
+ * `add` [#110](https://github.com/metabahn/corerb/pull/110) Introduce Core::Inspect::Inspectable for greater customization ([bryanp](https://github.com/bryanp))
12
+ * `chg` [#109](https://github.com/metabahn/corerb/pull/109) Prefer `__send__` to `send` ([bryanp](https://github.com/bryanp))
13
+
14
+ ## [v0.0.2](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
15
+
16
+ *released on 2021-11-02*
17
+
18
+ * `chg` [#97](https://github.com/metabahn/corerb/pull/97) Designate internal state with leading and trailing double underscores ([bryanp](https://github.com/bryanp))
19
+
1
20
  ## [v0.0.0](https://github.com/metabahn/corerb/releases/tag/2021-07-07)
2
21
 
3
22
  *released on 2021-07-07*
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Core
4
+ module Inspect
5
+ # [public]
6
+ #
7
+ class Inspection
8
+ def initialize(name:, resolver: name.to_s)
9
+ @name = name.to_s
10
+ @resolver = resolver
11
+ end
12
+
13
+ # [public]
14
+ #
15
+ attr_reader :name
16
+
17
+ # [public]
18
+ #
19
+ def resolve(context)
20
+ if @resolver.start_with?("@")
21
+ context.instance_variable_get(@resolver)
22
+ else
23
+ context.__send__(@resolver)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Inspect
5
- VERSION = "0.0.0"
5
+ VERSION = "0.1.1"
6
6
 
7
7
  def self.version
8
8
  VERSION
data/lib/core/inspect.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Core
4
4
  module Inspect
5
+ require_relative "inspect/inspection"
5
6
  require_relative "inspect/version"
6
7
  end
7
8
  end
@@ -4,6 +4,8 @@ require "is/extension"
4
4
  require "is/localized"
5
5
  require "is/stateful"
6
6
 
7
+ require_relative "../core/inspect/inspection"
8
+
7
9
  module Is
8
10
  # [public] Customized inspections for any object.
9
11
  #
@@ -12,29 +14,48 @@ module Is
12
14
 
13
15
  extends dependencies: [Is::Stateful]
14
16
 
15
- extends :class do
17
+ extends :definition do
16
18
  # [public] Sets one or more instance variables or instance methods as inspectable.
17
19
  #
18
20
  # without - An array of instance variables or instance methods that should not be inspected.
19
21
  #
20
22
  def inspects(*inspectables, without: [])
21
23
  if inspectables.any?
22
- mutate_state :__inspectables do |current_inspectables|
23
- current_inspectables.concat(inspectables.map(&:to_s)).uniq
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
24
31
  end
25
32
  end
26
33
 
27
34
  if without.any?
28
- mutate_state :__uninspectables do |current_uninspectables|
29
- current_uninspectables.concat(without.map(&:to_s)).uniq
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
30
42
  end
31
43
  end
32
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
33
54
  end
34
55
 
35
- applied do
36
- state :__inspectables, default: []
37
- state :__uninspectables, default: []
56
+ applies do
57
+ state :__inspectables__, default: {}
58
+ state :__uninspectables__, default: {}
38
59
  end
39
60
 
40
61
  # [public] Inspects the object.
@@ -47,13 +68,7 @@ module Is
47
68
  else
48
69
  Inspectable.prevent_recursion(self) do
49
70
  each_inspectable do |inspectable|
50
- value = if inspectable.start_with?("@")
51
- instance_variable_get(inspectable)
52
- else
53
- send(inspectable)
54
- end
55
-
56
- inspection << ", #{inspectable}=#{value.inspect}"
71
+ inspection << ", #{inspectable.name}=#{inspectable.resolve(self).inspect}"
57
72
  end
58
73
 
59
74
  inspection.strip << ">"
@@ -62,16 +77,18 @@ module Is
62
77
  end
63
78
 
64
79
  private def each_inspectable
65
- inspectables = if __inspectables.any?
66
- __inspectables
80
+ inspectables = if @__inspectables__.any?
81
+ @__inspectables__
67
82
  else
68
83
  instance_variables.map(&:to_s).reject { |instance_variable|
69
84
  instance_variable.start_with?("@_")
85
+ }.each_with_object({}) { |instance_variable, hash|
86
+ hash[instance_variable] = self.class.__send__(:build_inspection, instance_variable)
70
87
  }
71
88
  end
72
89
 
73
- inspectables.each do |inspectable|
74
- unless __uninspectables.include?(inspectable)
90
+ inspectables.each_value do |inspectable|
91
+ unless @__uninspectables__.include?(inspectable.name)
75
92
  yield inspectable
76
93
  end
77
94
  end
@@ -93,7 +110,7 @@ module Is
93
110
  end
94
111
 
95
112
  def inspected_objects
96
- localized(:__corerb_inspected_objects) || localize(:__corerb_inspected_objects, {})
113
+ localized(:__corerb_inspected_objects__) || localize(:__corerb_inspected_objects__, {})
97
114
  end
98
115
  end
99
116
  end
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.0.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-07 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.0'
19
+ version: '0.3'
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.0'
26
+ version: '0.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: core-local
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,6 +61,7 @@ files:
61
61
  - CHANGELOG.md
62
62
  - LICENSE
63
63
  - lib/core/inspect.rb
64
+ - lib/core/inspect/inspection.rb
64
65
  - lib/core/inspect/version.rb
65
66
  - lib/is/inspectable.rb
66
67
  homepage: https://github.com/metabahn/corerb/
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  - !ruby/object:Gem::Version
83
84
  version: '0'
84
85
  requirements: []
85
- rubygems_version: 3.2.15
86
+ rubygems_version: 3.3.3
86
87
  signing_key:
87
88
  specification_version: 4
88
89
  summary: Customized inspections for any object.