project_store 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 069f462f4419f33504821ad4e4527e9814aff1b2
4
- data.tar.gz: 517da8414736801a1116e59d12ac87f0fa4eeadc
3
+ metadata.gz: 68bf885a3948fba46055ea4b967e0ac9d313cc67
4
+ data.tar.gz: bba7870f3eda812689c6fa811549c8511285d5e1
5
5
  SHA512:
6
- metadata.gz: c2c7277e4dfd2c7a339ddaed06803909ede5e891bd146930b26bf4e228faa463e6c548682bd077398b20d7638c01dfadf995940716daa685790b6553c63b46b9
7
- data.tar.gz: ad9249bea80bfeccbacaeb7a513f9d0c99f5fdea1a6bbd8bdeb941f88fa2a5fc0f1418b13ebe85b3be40f9255e8af9e5d3e98def447d5bac16d8233e1e40093e
6
+ metadata.gz: 952a0808722a918c1b8c9a01c604d5818e4a66c2ecff42fc631311dd2b174f3be8f1e0aef34b5a36c4ab7ef864dee6021788573ae3909452a100a9cff4ab4339
7
+ data.tar.gz: ddf6e3cb95f019dee1a593c44a992be6ec194300fcf2f0c108f08821dbbacbf5c7debfade8690c1fc7bcd6e0982da49f8768ed6e43afe0f39de0b384c9c8bef1
@@ -21,7 +21,7 @@ module ProjectStore
21
21
  self.decorators = {}
22
22
  end
23
23
 
24
- def load_entities
24
+ def load_entities(&block)
25
25
  Dir.glob(File.join(path, '*.yaml')).each do |file|
26
26
  logger.debug "Found store file '#{file}'"
27
27
  begin
@@ -32,15 +32,14 @@ module ProjectStore
32
32
  begin
33
33
  logger.debug "Loading '#{entity_name}' entity."
34
34
  entity = store[entity_name]
35
- yield entity if block_given?
36
- decorate_and_index_entity entity_name, entity, store
35
+ decorate_and_index_entity entity_name, entity, store, &block
37
36
  rescue => e
38
37
  if continue_on_error
39
- logger.error "Invalid entity '#{entity_name}' in file '#{file}'"
38
+ logger.warn "Invalid entity '#{entity_name}' in file '#{file}'"
40
39
  logger.debug "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
41
40
  else
42
41
  logger.debug "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
43
- raise PSE, "Invalid entity '#{entity_name}' in file '#{file}'"
42
+ raise PSE, "Invalid entity '#{entity_name}' in file '#{file}' (#{e.message})"
44
43
  end
45
44
  end
46
45
  end
@@ -60,10 +59,10 @@ module ProjectStore
60
59
  Dir.exist? path and File.readable? path and File.writable? path
61
60
  end
62
61
 
63
- def decorate_and_index_entity(entity_name, entity, store)
64
- setup_entity! entity_name, entity
62
+ def decorate_and_index_entity(entity_name, entity, store, &block)
63
+ setup_entity! entity_name, entity, &block
65
64
  # Re-check the validity of the object now that it has been decorated
66
- entity.valid?(raise_exception: true)
65
+ entity.valid_to_load?(raise_exception: true)
67
66
  index_entity(entity, store)
68
67
  end
69
68
 
@@ -27,21 +27,23 @@ module ProjectStore
27
27
  tmp_file = Tempfile.new([self.class.name, '.yaml']).path
28
28
  begin
29
29
  FileUtils.copy file, tmp_file
30
- edit_file tmp_file, &block
31
- begin
30
+ edit_file tmp_file
31
+ # begin
32
32
  store = YAML::Store.new(tmp_file)
33
33
  store.transaction do
34
- store.roots.each do |entity_type|
35
- store[entity_type]
34
+ store.roots.each do |entity_name|
35
+ entity = store[entity_name]
36
+ setup_entity! entity_name, entity, &block
37
+ entity.valid_to_save? raise_exception: true
36
38
  end
37
39
  end
38
40
  FileUtils.copy tmp_file, file
39
41
  logger.info "File '#{file}' updated successfully."
40
42
  file
41
- rescue => e
42
- logger.debug "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
43
- raise PSE, 'Invalid modifications. Aborted !'
44
- end
43
+ # rescue => e
44
+ # logger.debug "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
45
+ # raise PSE, 'Invalid modifications. Aborted !'
46
+ # end
45
47
  ensure
46
48
  File.unlink tmp_file
47
49
  end
@@ -17,17 +17,36 @@ module ProjectStore
17
17
  ProjectStore.logger.warn "No backing store specified for '#{name}'. Not saved!"
18
18
  return false
19
19
  end
20
- valid? raise_exception: true
20
+ valid_to_save? raise_exception: true
21
21
  ProjectStore.logger.debug "Saving '#{name}' into '#{backing_store.path}'"
22
22
  backing_store.transaction do
23
23
  backing_store[name] = self
24
24
  end
25
25
  end
26
26
 
27
- def valid?(raise_exception: false)
27
+ def valid_to_load?(raise_exception: false)
28
28
  mandatory_properties.each do |mandatory_property|
29
29
  unless self[mandatory_property]
30
- raise_exception ? raise(PSE, "Invalid entity '#{name}'. Missing '#{mandatory_property}' property") : false
30
+ if raise_exception then
31
+ raise(PSE, "Invalid entity '#{name}'. Missing '#{mandatory_property}' property")
32
+ else
33
+ ProjectStore.logger.warn "Invalid entity '#{name}'. Missing '#{mandatory_property}' property"
34
+ false
35
+ end
36
+ end
37
+ end
38
+ true
39
+ end
40
+
41
+ def valid_to_save?(raise_exception: false)
42
+ mandatory_properties.each do |mandatory_property|
43
+ unless self[mandatory_property]
44
+ if raise_exception then
45
+ raise(PSE, "Invalid entity '#{name}'. Missing '#{mandatory_property}' property")
46
+ else
47
+ ProjectStore.logger.warn "Invalid entity '#{name}'. Missing '#{mandatory_property}' property"
48
+ false
49
+ end
31
50
  end
32
51
  end
33
52
  true
@@ -41,11 +60,11 @@ module ProjectStore
41
60
  raise PSE, 'Invalid entity. Missing name' unless name
42
61
  raise PSE, 'Invalid entity. You should not specify a name as it would not be taken in account' if self[:name]
43
62
 
44
- [:backing_store, :basic_checks, :save, :internal_type, :mandatory_properties, :valid?].each do |forbidden_name|
63
+ [:backing_store, :basic_checks, :save, :internal_type, :mandatory_properties, :valid_to_load?].each do |forbidden_name|
45
64
  raise PSE, "Invalid entity '#{name}'. Forbidden '#{forbidden_name}' property" if self[forbidden_name]
46
65
  end
47
66
 
48
- valid?(raise_exception: true)
67
+ valid_to_load?(raise_exception: true)
49
68
  end
50
69
 
51
70
  end
@@ -13,6 +13,7 @@ module ProjectStore
13
13
  ProjectStore.logger.info "New entity '#{entity.name}' of type '#{entity.type}'."
14
14
  # Adds extra decorator
15
15
  add_decorators entity
16
+ yield entity if block_given?
16
17
  entity
17
18
  end
18
19
 
@@ -1,3 +1,3 @@
1
1
  module ProjectStore
2
- VERSION = '0.6.7'
2
+ VERSION = '0.6.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: project_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent B.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler