mux_tf 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72d1bbf43fcbb38f0d1a8c4bba72321f582a4ff10ce75a49c87cef89e21647ac
4
- data.tar.gz: 2be9f70c1ce5a58df894866e02cd8efcfa04aa500ac394218368ef2bb88ee6fc
3
+ metadata.gz: '081eb21a5fe4e2b6af78aec28e0136cf68ef0301314e4b42c220feee51b12eb0'
4
+ data.tar.gz: b20cb57dc3c2cff965ba65dea8384ff91181c1716919cbf0330f91906c601fd1
5
5
  SHA512:
6
- metadata.gz: e64d359f26aafe4d2fd88f00d6294132ee1ed917a5bd02eda45500d55700327e7c70fad0a053b2007db2e350c822509288e1900ad30601571bce097795d70ae4
7
- data.tar.gz: 1c3b1ac826bace9b8191ce9ae55b392956ddb24e3d89d4aef86080799f408fd545d9efe4254e309a48515a9896e9f757ac20dc7938f42ee12d9f09a3a1a4cc8e
6
+ metadata.gz: 87ff57efa5e61617cbe4a65c57b09d2c3ee9741ff4ee93955bf015a3e76dc9dcb6cbb8f6d0ef2f419879e727bd3584827e98d88c68bd6af58af3808c8d53bf07
7
+ data.tar.gz: c8807d29c6839eac9496f4f8b4906e73b6b8f7504d1c888a9a003ff6b60eae3e77e65cf1f3932c62be8034551da3e8544f2ba30de90515e21578dbc87c529054
data/README.md CHANGED
@@ -31,7 +31,17 @@ ROOT/
31
31
 
32
32
  ## Development
33
33
 
34
- 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).
34
+ To install this gem onto your local machine, run `bundle exec rake install`.
35
+
36
+ ## Releasing
37
+
38
+ To release a new version, first bump the version number by running:
39
+
40
+ ```shell
41
+ gem bump -v major|minor|patch
42
+ ```
43
+
44
+ And then run `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).
35
45
 
36
46
  ## Contributing
37
47
 
@@ -23,6 +23,8 @@ require_relative './mux_tf/cli'
23
23
  require_relative './mux_tf/tmux'
24
24
  require_relative './mux_tf/terraform_helpers'
25
25
  require_relative './mux_tf/plan_formatter'
26
+ require_relative './mux_tf/version_check'
27
+ require_relative './mux_tf/yaml_cache'
26
28
 
27
29
  module MuxTf
28
30
  end
@@ -12,6 +12,8 @@ module MuxTf
12
12
 
13
13
  class << self
14
14
  def run(args)
15
+ version_check
16
+
15
17
  if args[0] == 'cli'
16
18
  cmd_loop
17
19
  return
@@ -57,6 +59,17 @@ module MuxTf
57
59
 
58
60
  private
59
61
 
62
+ def version_check
63
+ if VersionCheck.has_updates?
64
+ log Paint["="*80, :yellow]
65
+ log "New version of #{Paint["mux_tf", :cyan]} is available!"
66
+ log "You are currently on version: #{Paint[VersionCheck.current_gem_version, :yellow]}"
67
+ log "Latest version found is: #{Paint[VersionCheck.latest_gem_version, :green]}"
68
+ log "Run `#{Paint["gem update muf_tf", :green]}` to update!"
69
+ log Paint["="*80, :yellow]
70
+ end
71
+ end
72
+
60
73
  def run_validate
61
74
  remedies = PlanFormatter.process_validation(validate)
62
75
  process_remedies(remedies)
@@ -225,7 +238,7 @@ module MuxTf
225
238
 
226
239
  def interactive_cmd
227
240
  define_cmd('interactive', summary: 'Apply interactively') do |_opts, _args, _cmd|
228
- status = run_shell(['tf-plan-summary', PLAN_FILENAME, '-i'], return_status: true)
241
+ status = run_shell([tf_plan_summrary_cmd, PLAN_FILENAME, '-i'], return_status: true)
229
242
  if status != 0
230
243
  log 'Interactive Apply Failed!'
231
244
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuxTf
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,28 @@
1
+ module MuxTf
2
+ module VersionCheck
3
+ def has_updates?
4
+ current_gem_version < latest_gem_version
5
+ end
6
+
7
+ def latest_gem_version
8
+ value = cache.fetch("latest_gem_version") do
9
+ fetcher = Gem::SpecFetcher.fetcher
10
+ dependency = Gem::Dependency.new "mux_tf"
11
+ remotes, = fetcher.search_for_dependency dependency
12
+ remotes.map(&:first).map(&:version).sort.last.to_s
13
+ end
14
+
15
+ Gem::Version.new(value)
16
+ end
17
+
18
+ def current_gem_version
19
+ Gem::Version.new(MuxTf::VERSION)
20
+ end
21
+
22
+ def cache
23
+ @cache ||= YamlCache.new(File.expand_path("~/.mux_tf.yaml"), default_ttl: 1.hour)
24
+ end
25
+
26
+ extend self
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'yaml/store'
2
+
3
+ module MuxTf
4
+ class YamlCache
5
+ def initialize(path, default_ttl:)
6
+ @default_ttl = default_ttl
7
+ @store = YAML::Store.new path
8
+ end
9
+
10
+ def set(key, value, ttl: @default_ttl)
11
+ @store.transaction do
12
+ @store[key] = {
13
+ expires_at: Time.now + ttl,
14
+ value: value
15
+ }
16
+ end
17
+ end
18
+
19
+ def fetch(key, ttl: @default_ttl)
20
+ info = nil
21
+ @store.transaction(true) do
22
+ info = @store[key]
23
+ end
24
+
25
+ if info.nil? || info[:expires_at] < Time.now
26
+ if block_given?
27
+ value = yield
28
+ set(key, value, ttl: ttl)
29
+ return value
30
+ else
31
+ raise KeyError, info.nil? ? "no value at key: #{key}" : "value expired at key: #{key}"
32
+ end
33
+ end
34
+
35
+ info[:value]
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mux_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Banasik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-25 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -149,6 +149,8 @@ files:
149
149
  - lib/mux_tf/terraform_helpers.rb
150
150
  - lib/mux_tf/tmux.rb
151
151
  - lib/mux_tf/version.rb
152
+ - lib/mux_tf/version_check.rb
153
+ - lib/mux_tf/yaml_cache.rb
152
154
  - mux_tf.gemspec
153
155
  homepage: https://github.com/piotrb/mux_tf
154
156
  licenses: