Class: Marshalsea::Marshal::Node
- Inherits:
-
Object
- Object
- Marshalsea::Marshal::Node
- Defined in:
- lib/marshalsea/marshal/node.rb
Constant Summary collapse
- STRING_BACKED_TYPES =
%i[string regexp].freeze
- WRAPPER_TYPES =
%i[user_class extended].freeze
Instance Attribute Summary collapse
-
#auxiliary ⇒ Object
readonly
Returns the value of attribute auxiliary.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#instance_variable_pairs ⇒ Object
readonly
Returns the value of attribute instance_variable_pairs.
-
#instance_variables_map ⇒ Object
readonly
Returns the value of attribute instance_variables_map.
-
#link_target ⇒ Object
Returns the value of attribute link_target.
-
#regexp_options ⇒ Object
Returns the value of attribute regexp_options.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#undecoded_tail ⇒ Object
readonly
Returns the value of attribute undecoded_tail.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #dispatches_key_methods? ⇒ Boolean
- #each {|_self| ... } ⇒ Object
- #effective_class_name ⇒ Object
- #eql_dispatcher(seen = {}.compare_by_identity) ⇒ Object
- #fully_decoded? ⇒ Boolean
- #gated? ⇒ Boolean
- #hash_dispatcher(seen = {}.compare_by_identity) ⇒ Object
-
#initialize(type:, tag: nil, value: nil, class_name: nil, undecoded_tail: nil) ⇒ Node
constructor
A new instance of Node.
- #member_dispatcher(probe, seen) ⇒ Object
- #range_endpoints ⇒ Object
- #seal ⇒ Object
- #sink? ⇒ Boolean
- #sink_method ⇒ Object
- #string_backed? ⇒ Boolean
Constructor Details
#initialize(type:, tag: nil, value: nil, class_name: nil, undecoded_tail: nil) ⇒ Node
Returns a new instance of Node.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/marshalsea/marshal/node.rb', line 15 def initialize(type:, tag: nil, value: nil, class_name: nil, undecoded_tail: nil) @type = type @tag = tag @value = value @class_name = class_name @undecoded_tail = undecoded_tail @children = [] @instance_variables_map = {} @instance_variable_pairs = [] @auxiliary = [] end |
Instance Attribute Details
#auxiliary ⇒ Object (readonly)
Returns the value of attribute auxiliary.
11 12 13 |
# File 'lib/marshalsea/marshal/node.rb', line 11 def auxiliary @auxiliary end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
11 12 13 |
# File 'lib/marshalsea/marshal/node.rb', line 11 def children @children end |
#class_name ⇒ Object
Returns the value of attribute class_name.
13 14 15 |
# File 'lib/marshalsea/marshal/node.rb', line 13 def class_name @class_name end |
#instance_variable_pairs ⇒ Object (readonly)
Returns the value of attribute instance_variable_pairs.
11 12 13 |
# File 'lib/marshalsea/marshal/node.rb', line 11 def instance_variable_pairs @instance_variable_pairs end |
#instance_variables_map ⇒ Object (readonly)
Returns the value of attribute instance_variables_map.
11 12 13 |
# File 'lib/marshalsea/marshal/node.rb', line 11 def instance_variables_map @instance_variables_map end |
#link_target ⇒ Object
Returns the value of attribute link_target.
13 14 15 |
# File 'lib/marshalsea/marshal/node.rb', line 13 def link_target @link_target end |
#regexp_options ⇒ Object
Returns the value of attribute regexp_options.
13 14 15 |
# File 'lib/marshalsea/marshal/node.rb', line 13 def @regexp_options end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
11 12 13 |
# File 'lib/marshalsea/marshal/node.rb', line 11 def tag @tag end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/marshalsea/marshal/node.rb', line 11 def type @type end |
#undecoded_tail ⇒ Object (readonly)
Returns the value of attribute undecoded_tail.
11 12 13 |
# File 'lib/marshalsea/marshal/node.rb', line 11 def undecoded_tail @undecoded_tail end |
#value ⇒ Object
Returns the value of attribute value.
13 14 15 |
# File 'lib/marshalsea/marshal/node.rb', line 13 def value @value end |
Instance Method Details
#dispatches_key_methods? ⇒ Boolean
43 44 45 |
# File 'lib/marshalsea/marshal/node.rb', line 43 def dispatches_key_methods? !hash_dispatcher.nil? || !eql_dispatcher.nil? end |
#each {|_self| ... } ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/marshalsea/marshal/node.rb', line 95 def each(&block) return enum_for(:each) unless block yield self children.each { |child| child.each(&block) } auxiliary.each { |child| child.each(&block) } end |
#effective_class_name ⇒ Object
84 85 86 |
# File 'lib/marshalsea/marshal/node.rb', line 84 def effective_class_name link_target ? link_target.class_name : class_name end |
#eql_dispatcher(seen = {}.compare_by_identity) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/marshalsea/marshal/node.rb', line 58 def eql_dispatcher(seen = {}.compare_by_identity) return nil if seen.key?(self) seen[self] = true return link_target&.eql_dispatcher(seen) if type == :object_link return member_dispatcher(:eql_dispatcher, seen) unless class_name self end |
#fully_decoded? ⇒ Boolean
27 28 29 |
# File 'lib/marshalsea/marshal/node.rb', line 27 def fully_decoded? undecoded_tail.nil? end |
#gated? ⇒ Boolean
39 40 41 |
# File 'lib/marshalsea/marshal/node.rb', line 39 def gated? Constants::GATED_SINK_TAGS.include?(tag) end |
#hash_dispatcher(seen = {}.compare_by_identity) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/marshalsea/marshal/node.rb', line 47 def hash_dispatcher(seen = {}.compare_by_identity) return nil if seen.key?(self) seen[self] = true return link_target&.hash_dispatcher(seen) if type == :object_link return member_dispatcher(:hash_dispatcher, seen) unless class_name return nil if WRAPPER_TYPES.include?(type) && string_backed? self end |
#member_dispatcher(probe, seen) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/marshalsea/marshal/node.rb', line 68 def member_dispatcher(probe, seen) children.each do |child| found = child.public_send(probe, seen) return found if found end nil end |
#range_endpoints ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/marshalsea/marshal/node.rb', line 76 def range_endpoints instance_variable_pairs.filter_map do |name, value| next unless Constants::RANGE_ENDPOINT_IVARS.include?(name.value) value if value.effective_class_name end end |
#seal ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/marshalsea/marshal/node.rb', line 103 def seal value.freeze class_name.freeze undecoded_tail.freeze children.freeze auxiliary.freeze instance_variables_map.freeze instance_variable_pairs.freeze freeze end |
#sink? ⇒ Boolean
31 32 33 |
# File 'lib/marshalsea/marshal/node.rb', line 31 def sink? Constants::SINK_TAGS.include?(tag) end |
#sink_method ⇒ Object
35 36 37 |
# File 'lib/marshalsea/marshal/node.rb', line 35 def sink_method Constants::SINK_METHODS[tag] end |
#string_backed? ⇒ Boolean
88 89 90 91 92 93 |
# File 'lib/marshalsea/marshal/node.rb', line 88 def string_backed? wrapped = children.first return false unless wrapped STRING_BACKED_TYPES.include?(wrapped.type) end |