Class: Flatpack::Core::BaseHasUuid

Inherits:
Object
  • Object
show all
Includes:
MapInitialize
Defined in:
lib/flatpack/core/base_has_uuid.rb

Constant Summary collapse

PROPERTY_NAMES =
[:uuid]

Instance Method Summary collapse

Methods included from MapInitialize

#initialize, #set_properties

Instance Method Details

#<=>(other) ⇒ Object

Equality should be based solely on uuid



46
47
48
# File 'lib/flatpack/core/base_has_uuid.rb', line 46

def <=>(other)
  @uuid <=> other.uuid
end

#class_for_property(property) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/flatpack/core/base_has_uuid.rb', line 50

def class_for_property(property)
  klass=self.class
  result = nil
  while (klass and !result)
    result = klass::TYPE_MAP[property.to_sym] if defined? klass::TYPE_MAP
    klass = klass.superclass
  end
  result
end

#entity_nameObject

returns the flatpack entity name for this entity



40
41
42
43
# File 'lib/flatpack/core/base_has_uuid.rb', line 40

def entity_name
  name = self.class.name.gsub(/^.*::/,'')
  name[0,1].downcase + name[1..-1]
end

#propertiesObject

returns a hash of all flatpack property names => non-nil values for this entity



30
31
32
33
34
35
36
37
# File 'lib/flatpack/core/base_has_uuid.rb', line 30

def properties
  map = {}
  property_names.each do |name|
    value = self.send(name)
    map[name] = value unless value == nil
  end
  map
end

#property_namesObject

returns an array of all flatpack property names for this entity



19
20
21
22
23
24
25
26
27
# File 'lib/flatpack/core/base_has_uuid.rb', line 19

def property_names
  names = []
  klass=self.class
  while (klass)
    names += klass::PROPERTY_NAMES if defined? klass::PROPERTY_NAMES
    klass = klass.superclass
  end
  names
end

#uuidObject

returns this entity’s assigned uuid. If no uuid has been assigned, a new uuid will be generated and assigned before returning.



14
15
16
# File 'lib/flatpack/core/base_has_uuid.rb', line 14

def uuid 
  @uuid = @uuid || UUIDTools::UUID.random_create
end