Class: Rod::AbstractModel

Inherits:
Object
  • Object
show all
Defined in:
lib/rod/abstract_model.rb

Overview

A base class for all classes stored in the DataBase (both user defined and DB defined).

Direct Known Subclasses

JoinElement, Model, StringElement

Class Method Summary collapse

Class Method Details

.build_structure ⇒ Object

By default nothing is built.



30
31
# File 'lib/rod/abstract_model.rb', line 30

def self.build_structure
end

.cache ⇒ Object

Default cache for models.



34
35
36
# File 'lib/rod/abstract_model.rb', line 34

def self.cache
  @cache ||= Cache.new
end

.compatible?(metadata) ⇒ Boolean

Checks if the metadata are compatible with the class definition.

Returns:

  • (Boolean)


56
57
58
# File 'lib/rod/abstract_model.rb', line 56

def self.compatible?()
  self.difference().empty?
end

.difference(metadata) ⇒ Object

Calculates the difference between the classes metadata and the metadata provided.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rod/abstract_model.rb', line 62

def self.difference()
   = self.
   = .dup
  .delete(:count)
  result = []
  .each do |type,values|
    # TODO #161 the order of properties should be preserved for the
    # whole class, not only for each type of properties.
    if [:fields,:has_one,:has_many].include?(type)
      values.to_a.zip([type].to_a) do |meta1,meta2|
        if meta1 != meta2
          result << [meta2,meta1]
        end
      end
    else
      if [type] != values
        result << [[type],values]
      end
    end
  end
  result
end

.fields ⇒ Object

By default there are no fields.



25
26
27
# File 'lib/rod/abstract_model.rb', line 25

def self.fields
  []
end

.indexed_properties ⇒ Object

There are no indexed properties.



39
40
41
# File 'lib/rod/abstract_model.rb', line 39

def self.indexed_properties
  []
end

.layout ⇒ Object

Default implementation prints nothing.



21
22
# File 'lib/rod/abstract_model.rb', line 21

def self.layout
end

.metadata ⇒ Object

Returns meta-data (in the form of a hash) for the model.



49
50
51
52
53
# File 'lib/rod/abstract_model.rb', line 49

def self.
  meta = {}
  meta[:superclass] = self.superclass.name
  meta
end

.path_for_data(path) ⇒ Object

Path to the file storing the model data.



16
17
18
# File 'lib/rod/abstract_model.rb', line 16

def self.path_for_data(path)
  "#{path}#{self.struct_name}.dat"
end

.properties ⇒ Object

By default properties are empty.



44
45
46
# File 'lib/rod/abstract_model.rb', line 44

def self.properties
  []
end

.struct_name ⇒ Object

C-struct name of the model.

Raises:



11
12
13
# File 'lib/rod/abstract_model.rb', line 11

def self.struct_name
  raise RodException.new("#typdef_struct called for AbstractModel")
end

.typedef_struct ⇒ Object

Empty string.

Raises:



6
7
8
# File 'lib/rod/abstract_model.rb', line 6

def self.typedef_struct
  raise RodException.new("#typdef_struct called for AbstractModel")
end