Module: ProjectStore::Entity::Base
Instance Attribute Summary collapse
#name
Instance Method Summary
collapse
#mandatory_property, #yaml_accessor, #yaml_reader, #yaml_writer
Instance Attribute Details
#backing_store ⇒ Object
Returns the value of attribute backing_store.
8
9
10
|
# File 'lib/project_store/entity/base.rb', line 8
def backing_store
@backing_store
end
|
Instance Method Details
#basic_checks ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/project_store/entity/base.rb', line 74
def basic_checks
raise PSE, 'Invalid entity. Missing name' unless name
raise PSE, 'Invalid entity. You should not specify a name as it would not be taken in account' if self[:name]
[:backing_store, :basic_checks, :save, :internal_type, :mandatory_properties, :valid_to_load?].each do |forbidden_name|
raise PSE, "Invalid entity '#{name}'. Forbidden '#{forbidden_name}' property" if self[forbidden_name]
end
valid_to_load?(raise_exception: true)
end
|
#delete! ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/project_store/entity/base.rb', line 27
def delete!
if backing_store.nil?
ProjectStore.logger.warn "No backing store specified for '#{name}'. Not saved!"
return false
end
ProjectStore.logger.debug "Deleting '#{name}' from '#{backing_store.path}'"
backing_store.transaction do
backing_store.delete name
end
end
|
#mandatory_properties ⇒ Object
70
71
72
|
# File 'lib/project_store/entity/base.rb', line 70
def mandatory_properties
@mandatory_properties ||= [:type]
end
|
#save ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/project_store/entity/base.rb', line 15
def save
if backing_store.nil?
ProjectStore.logger.warn "No backing store specified for '#{name}'. Not saved!"
return false
end
valid_to_save? raise_exception: true
ProjectStore.logger.debug "Saving '#{name}' into '#{backing_store.path}'"
backing_store.transaction do
backing_store[name] = self
end
end
|
#valid?(raise_exception: false) ⇒ Boolean
66
67
68
|
# File 'lib/project_store/entity/base.rb', line 66
def valid?(raise_exception: false)
valid_to_save? raise_exception: raise_exception
end
|
#valid_to_load?(raise_exception: false) ⇒ Boolean
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/project_store/entity/base.rb', line 38
def valid_to_load?(raise_exception: false)
mandatory_properties.each do |mandatory_property|
unless self[mandatory_property]
if raise_exception then
raise(PSE, "Invalid entity '#{name}'. Missing '#{mandatory_property}' property")
else
ProjectStore.logger.warn "Invalid entity '#{name}'. Missing '#{mandatory_property}' property"
false
end
end
end
true
end
|
#valid_to_save?(raise_exception: false) ⇒ Boolean
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/project_store/entity/base.rb', line 52
def valid_to_save?(raise_exception: false)
mandatory_properties.each do |mandatory_property|
unless self[mandatory_property]
if raise_exception then
raise(PSE, "Invalid entity '#{name}'. Missing '#{mandatory_property}' property")
else
ProjectStore.logger.warn "Invalid entity '#{name}'. Missing '#{mandatory_property}' property"
false
end
end
end
true
end
|