module ProjectStore::Entity::Base

Attributes

backing_store[R]

Public Instance Methods

backing_store=(store) click to toggle source
# File lib/project_store/entity/base.rb, line 10
def backing_store=(store)
  raise PSE, 'Cannot change the store for an entity' if backing_store
  @backing_store = store
end
basic_checks() click to toggle source
# 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!() click to toggle source
# 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() click to toggle source
# File lib/project_store/entity/base.rb, line 70
def mandatory_properties
  @mandatory_properties ||= [:type]
end
save() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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