Class: DomainDriven::Entity

Inherits:
SimpleDelegator
  • Object
show all
Includes:
BlockActiveRecord
Defined in:
lib/domain_driven/entity.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BlockActiveRecord

#save, #save!, #update_attribute, #update_attribute!, #update_attributes, #update_attributes!

Class Method Details

.wrap(entity) ⇒ Object



35
36
37
# File 'lib/domain_driven/entity.rb', line 35

def self.wrap(entity)
  entity ? new(entity) : nil
end

.wraps(entities) ⇒ Object



39
40
41
42
# File 'lib/domain_driven/entity.rb', line 39

def self.wraps(entities)
  return nil unless entities
  wrap(entities.extend Model).extend Collection
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/domain_driven/entity.rb', line 19

def ==(other)
  if other.respond_to?(:_data)
    _data == other._data
  else
    _data == other
  end
end

#_dataObject



11
12
13
14
15
16
17
# File 'lib/domain_driven/entity.rb', line 11

def _data
  datum = self
  while datum.entity?
    datum = datum.__getobj__
  end
  datum
end

#classObject



31
32
33
# File 'lib/domain_driven/entity.rb', line 31

def class
  _data.class
end

#entity?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/domain_driven/entity.rb', line 27

def entity?
  true
end