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 collapse

/\[\[[\w-]+?:[!-~]+?(?:\[\] )?\]\]/

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, display_typemark, 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.



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

def initialize(db)
  @db = db
end

Class Method Details

.persistent_propertiesObject



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
69
# File 'lib/bitclust/entry.rb', line 22

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



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

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

Instance Method Details

#detail_sourceObject



209
210
211
# File 'lib/bitclust/entry.rb', line 209

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

#encodingObject



201
202
203
# File 'lib/bitclust/entry.rb', line 201

def encoding
  @db.encoding
end

#loaded?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/bitclust/entry.rb', line 197

def loaded?
  @loaded
end

#saveObject



213
214
215
216
217
218
# File 'lib/bitclust/entry.rb', line 213

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

#synopsis_sourceObject



205
206
207
# File 'lib/bitclust/entry.rb', line 205

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

#type_idObject



193
194
195
# File 'lib/bitclust/entry.rb', line 193

def type_id
  self.class.type_id
end