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
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/project_store/entity/base.rb', line 40
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?].each do |forbidden_name|
raise PSE, "Invalid entity '#{name}'. Forbidden '#{forbidden_name}' property" if self[forbidden_name]
end
valid?(raise_exception: true)
end
|
#mandatory_properties ⇒ Object
36
37
38
|
# File 'lib/project_store/entity/base.rb', line 36
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? 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
27
28
29
30
31
32
33
34
|
# File 'lib/project_store/entity/base.rb', line 27
def valid?(raise_exception: false)
mandatory_properties.each do |mandatory_property|
unless self[mandatory_property]
raise_exception ? raise(PSE, "Invalid entity '#{name}'. Missing '#{mandatory_property}' property") : false
end
end
true
end
|