Module: Loba::Internal::Value::ValueHelper Private
- Defined in:
- lib/loba/internal/value/value_helper.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Internal helper functions for Value.phrases
Class Method Summary collapse
-
.class_name(depth: 0) ⇒ String
private
Prepare display of class name from where Loba was invoked.
-
.evaluate(argument:, inspect: true, depth: 0) ⇒ Object
private
Evaluate an arguments value from where it’s bound.
-
.label(argument:, explicit_label: nil) ⇒ String
private
Builds a label for display based on the argument when instantiated.
-
.line(depth: 0) ⇒ Integer
private
Identify source code line from where Loba was invoked.
-
.method_name(depth: 0) ⇒ Symbol, String
private
Prepare display of method name from where Loba was invoked.
-
.method_type(depth: 0) ⇒ :class, :instance
private
Prepare display of whether the method from where Loba was invoked is for a class or an instance.
-
.tag(depth: 0) ⇒ String
private
Assemble display that shows the method invoking Loba.
-
.value(argument:, inspect: true, depth: 0) ⇒ String
private
Prepare display of an argument’s value.
Class Method Details
.class_name(depth: 0) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare display of class name from where Loba was invoked
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/loba/internal/value/value_helper.rb', line 90 def class_name(depth: 0) m = binding.of_caller(depth + 1).eval('self.class.name') if m.nil? || m.empty? '<anonymous class>' elsif m == 'Class' binding.of_caller(depth + 1).eval('self.name') else m end end |
.evaluate(argument:, inspect: true, depth: 0) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Evaluate an arguments value from where it’s bound.
80 81 82 83 84 85 |
# File 'lib/loba/internal/value/value_helper.rb', line 80 def evaluate(argument:, inspect: true, depth: 0) return inspect ? argument.inspect : argument unless argument.is_a?(Symbol) evaluation = binding.of_caller(depth + 1).eval(argument.to_s) inspect ? evaluation.inspect : evaluation end |
.label(argument:, explicit_label: nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a label for display based on the argument when instantiated. If the argument (when instantiated) is not a symbol, it may not be possible to infer a label; in that case, “[unknown value]”“ is returned.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/loba/internal/value/value_helper.rb', line 61 def label(argument:, explicit_label: nil) text = if explicit_label.nil? argument.is_a?(Symbol) ? "#{argument}:" : nil elsif explicit_label.respond_to?(:strip) s = explicit_label.strip s += ':' unless s[-1] == ':' s end text.nil? ? '[unknown value]:' : text.to_s end |
.line(depth: 0) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Identify source code line from where Loba was invoked
25 26 27 |
# File 'lib/loba/internal/value/value_helper.rb', line 25 def line(depth: 0) caller[depth] end |
.method_name(depth: 0) ⇒ Symbol, String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare display of method name from where Loba was invoked
117 118 119 120 |
# File 'lib/loba/internal/value/value_helper.rb', line 117 def method_name(depth: 0) m = binding.of_caller(depth + 1).eval('self.send(:__method__)') m.nil? || m.empty? ? '<anonymous method>' : m end |
.method_type(depth: 0) ⇒ :class, :instance
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare display of whether the method from where Loba was invoked is for a class or an instance
106 107 108 109 110 111 112 |
# File 'lib/loba/internal/value/value_helper.rb', line 106 def method_type(depth: 0) if binding.of_caller(depth + 1).eval('self.class.name') == 'Class' :class else :instance end end |
.tag(depth: 0) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Assemble display that shows the method invoking Loba
13 14 15 16 17 18 19 20 |
# File 'lib/loba/internal/value/value_helper.rb', line 13 def tag(depth: 0) delim = { class: '.', instance: '#' } '[' \ "#{class_name(depth: depth + 1)}" \ "#{delim[method_type(depth: depth + 1)]}" \ "#{method_name(depth: depth + 1)}" \ ']' end |
.value(argument:, inspect: true, depth: 0) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare display of an argument’s value.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/loba/internal/value/value_helper.rb', line 36 def value(argument:, inspect: true, depth: 0) val = evaluate(argument: argument, inspect: inspect, depth: depth + 1) # #inspect adds explicit quotes to strings, so strip back off since #inspect # always returns a String val = Loba::Internal.unquote(val) if inspect # make nils obvious val.nil? ? '-nil-' : val.to_s end |