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.


82
83
84
85
# File 'lib/bitclust/entry.rb', line 82

def initialize(name, type)
  @name = name
  @type = type
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

Instance Method Details

#deserializerObject


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/bitclust/entry.rb', line 106

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}'])"
  else
    raise "must not happen: @type=#{@type.inspect}"
  end
end

#initial_valueObject


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/bitclust/entry.rb', line 89

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 "[]"
  else
    raise "must not happen: @type=#{@type.inspect}"
  end
end

#serializerObject


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/bitclust/entry.rb', line 123

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})"
  else
    raise "must not happen: @type=#{@type.inspect}"
  end
end