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 +4 -4
- data/.travis.yml +2 -0
- data/README.md +22 -6
- data/lib/project_store/editing.rb +41 -27
- data/lib/project_store/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e14c2c57045fc7b870aee3abc5d80ce5a50337b2
|
4
|
+
data.tar.gz: 29ac6c2d7c6aaf39a136a7f7b865ba1b749fa471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4707b6b39ba31f32a2f3426fa6740c92a769152dd1831e22af5df9f1f632801d68fb1039e07099e0569565fb6fd36ea55e9c93541d6c6ff4a21b964997218db3
|
7
|
+
data.tar.gz: 7bc33d14d4a7cd9a47963b1b71979498c99fd949d59162ad826bc5b0d3e5b6ef80e41d70b5ad0137c7eb71ba911b080d953fa0daa153e2c72a8eb6b4f8eaa369
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
# ProjectStore
|
2
2
|
|
3
|
-
|
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
|
-
|
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.
|
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,
|
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/
|
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 =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
38
|
+
retry_count ||= 1
|
39
|
+
FileUtils.copy file, tmp_file if retry_count == 1
|
30
40
|
edit_file tmp_file
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
|
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.
|
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:
|
11
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|