Class: BitClust::Entry

Inherits:
Object show all
Includes:
NameUtils, DRb::DRbUndumped
Defined in:
lib/bitclust/entry.rb,
lib/bitclust/server.rb

Overview

reopen

Defined Under Namespace

Classes: Property

Constant Summary

Constants included from NameUtils

NameUtils::CHAR_TO_MARK, NameUtils::CHAR_TO_NAME, NameUtils::CLASS_NAME_RE, NameUtils::CLASS_PATH_RE, NameUtils::CONST_PATH_RE, NameUtils::CONST_RE, NameUtils::GVAR_RE, NameUtils::LIBNAME_RE, NameUtils::MARK_TO_CHAR, NameUtils::MARK_TO_NAME, NameUtils::METHOD_NAME_RE, NameUtils::METHOD_SPEC_RE, NameUtils::MID, NameUtils::NAME_TO_CHAR, NameUtils::NAME_TO_MARK, NameUtils::TYPEMARK_RE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NameUtils

build_method_id, classid2name, classname2id, classname?, decodeid, decodename_fs, decodename_url, encodeid, encodename_fs, encodename_rdocurl, encodename_url, functionname?, gvarname?, html_filename, libid2name, libname2id, libname?, method_spec?, methodid2classid, methodid2libid, methodid2mname, methodid2specparts, methodid2specstring, methodid2typechar, methodid2typemark, methodid2typename, methodname?, split_method_id, split_method_spec, typechar2mark, typechar2name, typechar?, typemark2char, typemark2name, typemark?, typename2char, typename2mark, typename?

Constructor Details

#initialize(db) ⇒ Entry

Returns a new instance of Entry.


145
146
147
# File 'lib/bitclust/entry.rb', line 145

def initialize(db)
  @db = db
end

Class Method Details

.persistent_propertiesObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bitclust/entry.rb', line 21

def self.persistent_properties
  @slots = []
  yield
  sep = ";"
  module_eval(src = <<-End, __FILE__, __LINE__ + 1)
    def init_properties
      if saved?
        #{@slots.map {|s| "@#{s.name} = nil" }.join(sep)}
        @loaded = false
      else
        clear
      end
    end

    def clear
      #{@slots.map {|s| "@#{s.name} = #{s.initial_value}" }.join(sep)}
      @loaded = true
    end

    def _set_properties(h)
      #{@slots.map {|s| "@#{s.name} = #{s.deserializer}" }.join(sep)}
    end

    def _get_properties
      h = {}
      #{@slots.map {|s| "h['#{s.name}'] = #{s.serializer}" }.join(sep)}
      h
    end

    def unload
      clear
      @loaded = false
    end
  End
  @slots.each do |slot|
    module_eval(<<-End, __FILE__, __LINE__ + 1)
      def #{slot.name}
        load unless @loaded
        @#{slot.name}
      end

      def #{slot.name}=(value)
        load unless @loaded
        @#{slot.name} = value
      end
    End
  end
end

.property(name, type) ⇒ Object


70
71
72
# File 'lib/bitclust/entry.rb', line 70

def self.property(name, type)
  @slots.push Property.new(name, type)
end

Instance Method Details

#detail_sourceObject


165
166
167
# File 'lib/bitclust/entry.rb', line 165

def detail_source
  source().split(/\n\n/, 2)[1] || ''
end

#encodingObject


157
158
159
# File 'lib/bitclust/entry.rb', line 157

def encoding
  @db.encoding
end

#loaded?Boolean

Returns:

  • (Boolean)

153
154
155
# File 'lib/bitclust/entry.rb', line 153

def loaded?
  @loaded
end

#saveObject


169
170
171
172
173
174
# File 'lib/bitclust/entry.rb', line 169

def save
  @db.save_properties objpath(), _get_properties()
rescue Errno::ENOENT
  @db.makepath File.dirname(objpath())
  retry
end

#synopsis_sourceObject


161
162
163
# File 'lib/bitclust/entry.rb', line 161

def synopsis_source
  source().split(/\n\n/, 2).first || ''
end

#type_idObject


149
150
151
# File 'lib/bitclust/entry.rb', line 149

def type_id
  self.class.type_id
end