Class: TwistlockControl::PersistedEntity
- Inherits:
-
Entity
- Object
- Entity
- TwistlockControl::PersistedEntity
show all
- Defined in:
- lib/twistlock_control/entity.rb
Overview
A persisted entity is an entity that has its own persistant storage repository.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Entity
#==, #serialize
Class Method Details
.all ⇒ Object
34
35
36
|
# File 'lib/twistlock_control/entity.rb', line 34
def self.all
repository.all.map { |a| deserialize a }
end
|
.deserialize(attrs) ⇒ Object
25
26
27
28
|
# File 'lib/twistlock_control/entity.rb', line 25
def self.deserialize(attrs)
return nil if attrs.nil?
new(attrs)
end
|
.find_by_id(id) ⇒ Object
21
22
23
|
# File 'lib/twistlock_control/entity.rb', line 21
def self.find_by_id(id)
deserialize repository.find_by_id(id)
end
|
.find_with_ids(ids) ⇒ Object
30
31
32
|
# File 'lib/twistlock_control/entity.rb', line 30
def self.find_with_ids(ids)
repository.find_with_ids(ids).map { |a| deserialize a }
end
|
.inherited(subclass) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/twistlock_control/entity.rb', line 50
def self.inherited(subclass)
subclass.class_exec do
def self.repository(repository = nil)
return @repository = repository if repository
return @repository if @repository
return superclass.repository if superclass.respond_to?(:repository)
fail "#{name} has not defined a repository."
end
end
super(subclass)
end
|
Instance Method Details
#remove ⇒ Object
42
43
44
|
# File 'lib/twistlock_control/entity.rb', line 42
def remove
repository.remove(id)
end
|
#repository ⇒ Object
46
47
48
|
# File 'lib/twistlock_control/entity.rb', line 46
def repository
self.class.repository
end
|
#save ⇒ Object
38
39
40
|
# File 'lib/twistlock_control/entity.rb', line 38
def save
repository.save(serialize)
end
|