chef_cached_app_info 0.1.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 +7 -0
- data/lib/chef_cached_app_info.rb +41 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a47de09c0ed3701cac0e5a1cfb440dc2eb0e289b16bd23ab6d8db5699879740d
|
4
|
+
data.tar.gz: e11ec18af6793b235e66f8105384b1455182f2747169c4da6a72963c1468337c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99354cec2b999bd0497634d388a80f90b090e5b9e7d458fb28bcc995794630aa5332b91a4296e1b520b6d3e7478d9d2714003d012cd1d6460efbb8e9ca918b44
|
7
|
+
data.tar.gz: b4971cae84dd2b5359f78aa6b88fe64893e12808f062ea7142eca41b56095b6fb865ea0a8b6521504856af8d038253f6244fa34b1b667435ba918067626f8ad1
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class AppCache
|
4
|
+
def self.at(cookbook_path)
|
5
|
+
AppCache.new(cookbook_path)
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(cookbook_path)
|
9
|
+
@cookbook_path = cookbook_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def cache_versions(origin_file)
|
13
|
+
cached_app_info('app_version', origin_file)
|
14
|
+
cached_app_info('cookbook_version', origin_file, lambda { |x| x.gsub(/[^0-9.]/i, '') })
|
15
|
+
end
|
16
|
+
|
17
|
+
def cached_app_info(key, origin_file = nil, content_lambda = lambda { |x| x })
|
18
|
+
# Cache the original piece of info generated when building the app, so we have it when the app & infra are separated.
|
19
|
+
write_info(key, content_lambda.call(IO.read(origin_file).strip)) if origin_file != nil && File.exist?(origin_file)
|
20
|
+
# Cached version must always exist
|
21
|
+
value = cached_app_info_object[key]
|
22
|
+
raise "The cached app information stored by #{key} could not be found." if value.nil?
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
def cached_app_info_file
|
27
|
+
info_file = File.join(@cookbook_path, 'cached_app_info.json')
|
28
|
+
IO.write(info_file, '{}') unless File.exist?(info_file)
|
29
|
+
info_file
|
30
|
+
end
|
31
|
+
|
32
|
+
def cached_app_info_object
|
33
|
+
JSON.parse(File.read(cached_app_info_file))
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_info(key, value)
|
37
|
+
info = cached_app_info_object
|
38
|
+
info[key] = value
|
39
|
+
IO.write(cached_app_info_file, info.to_json)
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef_cached_app_info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- foxfire206
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Cache info for role cookbooks in Chef.
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/chef_cached_app_info.rb
|
20
|
+
homepage: http://rubygems.org/gems/chef_cached_app_info
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Cache info for role cookbooks in Chef.
|
44
|
+
test_files: []
|