Module: ProjectStore::Entity::Base

Includes:
MandatoryProperties
Defined in:
lib/project_store/entity/base.rb

Instance Attribute Summary collapse

Attributes included from MandatoryProperties

#name

Instance Method Summary collapse

Methods included from PropertyBinder

#mandatory_property, #yaml_accessor, #yaml_reader, #yaml_writer

Instance Attribute Details

#backing_storeObject

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_checksObject

Raises:



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_propertiesObject



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

def mandatory_properties
  @mandatory_properties ||= [:type]
end

#saveObject



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

Returns:

  • (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