core-inspect 0.0.2 → 0.1.0

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: 8cbeeb594ebe68c5deb082181273cda6e5bd54f1ef25dc0efa13a5fd824ed65c
4
- data.tar.gz: b47f293f1c54b870f7b0fb08a23746b8c814941ab06e9fc11cf2b3897031a82d
3
+ metadata.gz: 615476710018bff02b4d41a3671bc153b79e3cd9ad68fde4fff8c80b6313263b
4
+ data.tar.gz: 3ce099faddcbe11e82f7de1acbb18fec0200a4525cf72c606aaf97503043c7e6
5
5
  SHA512:
6
- metadata.gz: 44ddff2d8acfe055771918564e6ea2b67cc2e4bd837c7d072156e5384a8d727d477e1140f57cdab9227093006beeb89abed1add8e8391dd4e3fc873ead34cdfa
7
- data.tar.gz: d2d72c906922250d42f6820968f411c699849a7578f89139cab4f4a18b85774805bcf717ed274e176d33afa4247370e06c2c69cc9fa727c3db1c1e47392e1aef
6
+ metadata.gz: 9ef18b5f03f05496601ce8642dd72a38f16696b88d72e13eda75549ee3e754fd4de34733ee8c1ca2cf863847d812f7a5798b1eb1bc12bcb9fc21c94072ddcceb
7
+ data.tar.gz: c61999af7e3408936794246655542317b95aa63910ac0a6a872df552caeb1807f7197ff6087ebc27e86b12dc1e1484c74e40848466e876727bbe7f5e082f72d0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [v0.1.0](https://github.com/metabahn/corerb/releases/tag/2021-11-23.1)
2
+
3
+ *released on 2021-11-23.1*
4
+
5
+ * `add` [#110](https://github.com/metabahn/corerb/pull/110) Introduce Core::Inspect::Inspectable for greater customization ([bryanp](https://github.com/bryanp))
6
+ * `chg` [#109](https://github.com/metabahn/corerb/pull/109) Prefer `__send__` to `send` ([bryanp](https://github.com/bryanp))
7
+
1
8
  ## [v0.0.2](https://github.com/metabahn/corerb/releases/tag/2021-11-02)
2
9
 
3
10
  *released on 2021-11-02*
@@ -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.2"
5
+ VERSION = "0.1.0"
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
  #
@@ -20,21 +22,40 @@ module Is
20
22
  def inspects(*inspectables, without: [])
21
23
  if inspectables.any?
22
24
  mutate_state :__inspectables__ do |current_inspectables|
23
- current_inspectables.concat(inspectables.map(&:to_s)).uniq
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
35
  mutate_state :__uninspectables__ do |current_uninspectables|
29
- current_uninspectables.concat(without.map(&:to_s)).uniq
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
56
  applies do
36
- state :__inspectables__, default: []
37
- state :__uninspectables__, default: []
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 << ">"
@@ -67,11 +82,13 @@ module Is
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
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.2
4
+ version: 0.1.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: 2021-11-02 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: core-extension
@@ -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/