project_store 0.7.0 → 0.8.0

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: 4819203c3889f05232a0afd13a05894d3077cf1a
4
- data.tar.gz: c2f6683a99c1d3f19dfc5bdcef92b223ceb24403
3
+ metadata.gz: e14c2c57045fc7b870aee3abc5d80ce5a50337b2
4
+ data.tar.gz: 29ac6c2d7c6aaf39a136a7f7b865ba1b749fa471
5
5
  SHA512:
6
- metadata.gz: f4531161effa7a1c94176481a6b800a308f3e7814d929e7674ccf718dc061b6914e1fc248cf34aa0ec70bc4308c81ddddbf69a2c7fc56ca65f66b3a52fc5cef7
7
- data.tar.gz: 3ddf7c1396fcc60206e03ee0f56f37330b0b8ec86698f3134983db6e6a9c3a621e77025ed55da5b6c35c8d8905c07e241e8c805af38524e3c4c06a62c58342ec
6
+ metadata.gz: 4707b6b39ba31f32a2f3426fa6740c92a769152dd1831e22af5df9f1f632801d68fb1039e07099e0569565fb6fd36ea55e9c93541d6c6ff4a21b964997218db3
7
+ data.tar.gz: 7bc33d14d4a7cd9a47963b1b71979498c99fd949d59162ad826bc5b0d3e5b6ef80e41d70b5ad0137c7eb71ba911b080d953fa0daa153e2c72a8eb6b4f8eaa369
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.4
4
4
  before_install: gem install bundler -v 1.11.2
5
+ script:
6
+ - bundle exec rspec -f d 2> /dev/null
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # ProjectStore
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/project_store`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ `project_store` is a simple gem to persist a collection of Ruby objects in a Yaml based backing store.
4
+ As opposed to standard Yaml persistence mechanisms, the dump/reload mechanism is based on the `type` (as
5
+ in the `type` property) of objects.
6
+
7
+ All objects are actually pure hashes "decorated" by some modules depending on their `type` property.
8
+
9
+ By default any object loaded from a store will have the `ProjectStore::Entity::Base` module "applied" (the hash read
10
+ from the yaml backend will extend that module).
4
11
 
5
- TODO: Delete this and the text above, and describe your gem
6
12
 
7
13
  ## Installation
8
14
 
@@ -22,20 +28,30 @@ Or install it yourself as:
22
28
 
23
29
  ## Usage
24
30
 
25
- TODO: Write usage instructions here
31
+ The only real two objects you have to use are:
32
+
33
+ * `ProjectStore::Base` which represents a yaml datastore
34
+ * `ProjectStore::Entity::Base` which represents a basic object loaded from yaml
26
35
 
27
36
  ## Development
28
37
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec #BUNDLE_SSL_CA_CERT: '/etc/ssl/certs/NanonetRootCA.pem'` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ After checking out the repo, run `bin/setup` to install dependencies.
39
+ Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will
40
+ allow you to experiment.
30
41
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version,
43
+ update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a
44
+ git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
45
 
33
46
  ## Contributing
34
47
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/project_store. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lbriais/project_store.
49
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are
50
+ expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
51
 
37
52
 
38
53
  ## License
39
54
 
40
55
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
56
 
57
+
@@ -6,45 +6,59 @@ module ProjectStore
6
6
  module Editing
7
7
 
8
8
  EDITOR_ENVIRONMENT_VARIABLE = 'DM_EDITOR'
9
+ EDIT_RETRY_ENVIRONMENT_VARIABLE = 'DM_EDIT_RETRY'
10
+ DEFAULT_RETRY_MAX_COUNT = 1
11
+ ERROR_FILE_KEPT = '/tmp/last-failed-edit.yaml'
9
12
 
10
- attr_writer :editor
13
+ attr_writer :editor, :nb_max_edit_retries
11
14
 
12
15
  def editor
13
16
  @editor ||= ENV[EDITOR_ENVIRONMENT_VARIABLE]
14
17
  end
15
18
 
19
+ def nb_max_edit_retries
20
+ default = ENV[EDIT_RETRY_ENVIRONMENT_VARIABLE].to_i unless ENV[EDIT_RETRY_ENVIRONMENT_VARIABLE].nil?
21
+ default ||= DEFAULT_RETRY_MAX_COUNT
22
+ @nb_max_edit_retries ||= default
23
+ end
24
+
16
25
  def edit(file_or_entity, &block)
17
- file = case file_or_entity
18
- when String
19
- if File.exists? file_or_entity and File.readable? file_or_entity
20
- file_or_entity
21
- else
22
- raise PSE, "Invalid file to edit '#{file_or_entity}'"
23
- end
24
- when ProjectStore::Entity::Base
25
- file_or_entity.backing_store.path
26
- end
26
+ file = case file_or_entity
27
+ when String
28
+ if File.exists? file_or_entity and File.readable? file_or_entity
29
+ file_or_entity
30
+ else
31
+ raise PSE, "Invalid file to edit '#{file_or_entity}'"
32
+ end
33
+ when ProjectStore::Entity::Base
34
+ file_or_entity.backing_store.path
35
+ end
27
36
  tmp_file = Tempfile.new([self.class.name, '.yaml']).path
28
37
  begin
29
- FileUtils.copy file, tmp_file
38
+ retry_count ||= 1
39
+ FileUtils.copy file, tmp_file if retry_count == 1
30
40
  edit_file tmp_file
31
- # begin
32
- store = YAML::Store.new(tmp_file)
33
- store.transaction do
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
38
- end
41
+
42
+ store = YAML::Store.new(tmp_file)
43
+ store.transaction do
44
+ store.roots.each do |entity_name|
45
+ entity = store[entity_name]
46
+ setup_entity! entity_name, entity, &block
47
+ entity.valid_to_save? raise_exception: true
39
48
  end
40
- FileUtils.copy tmp_file, file
41
- logger.info "File '#{file}' updated successfully."
42
- file
43
- # rescue => e
44
- # logger.debug "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
45
- # raise PSE, 'Invalid modifications. Aborted !'
46
- # end
49
+ end
50
+ FileUtils.copy tmp_file, file
51
+ logger.info "File '#{file}' updated successfully."
52
+ file
53
+ rescue StandardError => e
54
+ retry_count += 1
55
+ retry unless retry_count > nb_max_edit_retries
56
+ raise e
47
57
  ensure
58
+ if retry_count > nb_max_edit_retries
59
+ logger.error "Keeping file '#{ERROR_FILE_KEPT}' which was invalid !"
60
+ FileUtils.copy tmp_file, ERROR_FILE_KEPT
61
+ end
48
62
  File.unlink tmp_file
49
63
  end
50
64
 
@@ -1,3 +1,3 @@
1
1
  module ProjectStore
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
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.7.0
4
+ version: 0.8.0
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-09-20 00:00:00.000000000 Z
11
+ date: 2017-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler