Class: BitClust::Entry::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/bitclust/entry.rb

Overview

Used to define specific property of each entry class.

Example

persistent_properties {
  property :requires, '[LibraryEntry]'
  property :classes,  '[ClassEntry]'
  ...

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



88
89
90
# File 'lib/bitclust/entry.rb', line 88

def name
  @name
end

Instance Method Details

#deserializerObject



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_valueObject



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

#serializerObject



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