Class: BitClust::Entry::Property
Overview
Used to define specific property of each entry class.
Example
persistent_properties {
property :requires, '[LibraryEntry]'
property :classes, '[ClassEntry]'
...
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #deserializer ⇒ Object
- #initial_value ⇒ Object
-
#initialize(name, type) ⇒ Property
constructor
A new instance of Property.
- #serializer ⇒ Object
Constructor Details
#initialize(name, type) ⇒ Property
Returns a new instance of Property.
83 84 85 86 |
# File 'lib/bitclust/entry.rb', line 83 def initialize(name, type) @name = name @type = type end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
88 89 90 |
# File 'lib/bitclust/entry.rb', line 88 def name @name end |
Instance Method Details
#deserializer ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/bitclust/entry.rb', line 108 def deserializer case @type when 'String' then "h['#{@name}']" when 'Symbol' then "h['#{@name}'].intern" when 'bool' then "h['#{@name}'] == 'true' ? true : false" when 'LibraryEntry' then "restore_library(h['#{@name}'])" when 'ClassEntry' then "restore_class(h['#{@name}'])" when 'MethodEntry' then "restore_method(h['#{@name}'])" when '[String]' then "h['#{@name}'].split(/,(?=.)/)" when '[LibraryEntry]' then "restore_libraries(h['#{@name}'])" when '[ClassEntry]' then "restore_classes(h['#{@name}'])" when '[MethodEntry]' then "restore_methods(h['#{@name}'])" when 'Location' then "h['#{@name}']&.tap { |loc| break if loc.empty?; break Location.new(*loc.split(?:)) }" else raise "must not happen: @type=#{@type.inspect}" end end |
#initial_value ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bitclust/entry.rb', line 90 def initial_value case @type when 'String' then "'(uninitialized)'" when 'Symbol' then "nil" when 'bool' then "false" when 'LibraryEntry' then "nil" when 'ClassEntry' then "nil" when 'MethodEntry' then "nil" when '[String]' then "[]" when '[LibraryEntry]' then "[]" when '[ClassEntry]' then "[]" when '[MethodEntry]' then "[]" when 'Location' then "nil" else raise "must not happen: @type=#{@type.inspect}" end end |
#serializer ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/bitclust/entry.rb', line 126 def serializer case @type when 'String' then "@#{@name}" when 'Symbol' then "@#{@name}.to_s" when 'bool' then "@#{@name}.to_s" when 'LibraryEntry' then "serialize_entry(@#{@name})" when 'ClassEntry' then "serialize_entry(@#{@name})" when 'MethodEntry' then "serialize_entry(@#{@name})" when '[String]' then "@#{@name}.join(',')" when '[LibraryEntry]' then "serialize_entries(@#{@name})" when '[ClassEntry]' then "serialize_entries(@#{@name})" when '[MethodEntry]' then "serialize_entries(@#{@name})" when 'Location' then "@#@name.to_s" else raise "must not happen: @type=#{@type.inspect}" end end |