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:



59
60
61
62
63
64
65
66
67
68
# File 'lib/project_store/entity/base.rb', line 59

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

#mandatory_propertiesObject



55
56
57
# File 'lib/project_store/entity/base.rb', line 55

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_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_to_load?(raise_exception: false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/project_store/entity/base.rb', line 27

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

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/project_store/entity/base.rb', line 41

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