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



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

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

.wraps(entities) ⇒ Object



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

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

#_real_classObject



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

alias :_real_class :class

#classObject



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

def class
  _data.class
end

#entity?Boolean

Returns:

  • (Boolean)


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

def entity?
  true
end