qb 0.1.69 → 0.1.70

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: d67fbe281a2360e617563b65cff02b777e5fe0ea
4
- data.tar.gz: fdb83e48ac561d01d86f4943a29e79903a58f7b3
3
+ metadata.gz: a96dba86d6f78961f1b98a546a2c322344b2e16f
4
+ data.tar.gz: c1ce84a3f5d8d5864c6f0a72e30eb119188803da
5
5
  SHA512:
6
- metadata.gz: 5187065635c8f370f0de852ece43088bd20320e70984a592a175452b97b151565c69b93f8fe0ad62e4b7d654e7b206e20c766172e65f633b338d688b7f284ff8
7
- data.tar.gz: 7139f9c5b84e21165ba26f0627f7dedddbeeb17803933bd55545585c058b935fd3622d4ce4d6b9ce35f0387ddcf2c73242384534ddfd13ed75023ae257a5ee57
6
+ metadata.gz: 986b7bf9fdea777e0d32bf5c7cad71d1842917c6c98ca58423121eb3e1a076024f949ce339025a24580afd97da005faa11b7646ffc6f9413d9d2537b8dfba8c9
7
+ data.tar.gz: 2e378c83dc28305371a331d889302a93206920422907fea50e067d1a2d813af67a1d7c277bfefe222a5e90865435c83111321549f15f02b127c1034e3d26aac3
data/exe/qb CHANGED
@@ -126,6 +126,8 @@ def main args
126
126
  exit 1
127
127
  end
128
128
 
129
+ QB.check_qb_version role
130
+
129
131
  options = QB::Options.new role, args
130
132
 
131
133
  QB.debug "role options set on cli", options.role_options.select {|k, o|
data/lib/qb.rb CHANGED
@@ -1,18 +1,16 @@
1
1
  require 'nrser/extras'
2
2
 
3
- require "qb/version"
4
- require "qb/util"
5
- require 'qb/util/stdio'
6
- require "qb/ansible_module"
3
+ require_relative './qb/errors'
4
+ require_relative "./qb/version"
5
+ require_relative "./qb/util"
6
+ require_relative './qb/util/stdio'
7
+ require_relative "./qb/ansible_module"
7
8
 
8
9
  module QB
9
10
  ROOT = (Pathname.new(__FILE__).dirname + '..').expand_path
10
11
  GEM_ROLES_DIR = ROOT + 'roles'
11
12
  USER_ROLES_DIR = Pathname.new(ENV['HOME']).join '.ansible', 'roles'
12
- MIN_ANSIBLE_VERSION = Gem::Version.new '2.1.2'
13
13
 
14
- class Error < StandardError
15
- end
16
14
 
17
15
  def self.debug *args
18
16
  return unless ENV['QB_DEBUG'] && args.length > 0
@@ -35,28 +33,7 @@ module QB
35
33
  # $stderr.puts("DEBUG " + format(msg, values))
36
34
  $stderr.puts dumpObj.pretty_inspect
37
35
  end
38
-
39
- def self.check_ansible_version
40
- out = Cmds.out! 'ansible --version'
41
- version_str = out[/ansible\ ([\d\.]+)/, 1]
42
-
43
- if version_str.nil?
44
- raise NRSER.dedent <<-END
45
- could not parse ansible version from `ansible --version` output:
46
-
47
- #{ out }
48
- END
49
- end
50
36
 
51
- version = Gem::Version.new version_str
52
-
53
- if version < QB::MIN_ANSIBLE_VERSION
54
- raise NRSER.squish <<-END
55
- qb #{ QB::VERSION } requires ansible #{ QB::MIN_ANSIBLE_VERSION },
56
- found version #{ version_str } at #{ `which ansible` }
57
- END
58
- end
59
- end
60
37
  end
61
38
 
62
39
  # needs QB::*_ROLES_DIR
@@ -0,0 +1,19 @@
1
+ module QB
2
+ # Base class for QB errors.
3
+ class Error < StandardError; end
4
+
5
+ # Raised when a version mismatch occurs.
6
+ class VersionError < Error; end
7
+
8
+ # Raised when the current Ansible version doesn't satisfy:
9
+ #
10
+ # 1. A role as defined in `<role_dir>/meta/main.yml:min_ansible_version`)
11
+ #
12
+ # 2. QB itself as defined in {QB::MIN_ANSIBLE_VERSION}
13
+ #
14
+ class AnsibleVersionError < VersionError; end
15
+
16
+ # Raised when the current QB version doesn't satisfy a role as defined
17
+ # in `<role_dir>/meta/qb[.yml]:required_qb_version`).
18
+ class QBVersionError < VersionError; end
19
+ end # module QB
@@ -617,6 +617,23 @@ module QB
617
617
  meta_or 'ansible_options', {}
618
618
  end
619
619
 
620
+
621
+ # Get the {Gem::Requirement} parse of the `qb_requirement` key in
622
+ # {#meta} (if it is defined), which specifies the required version of
623
+ # `qb` for the role.
624
+ #
625
+ # @return [Gem::Requirement, nil]
626
+ # The requirement if `required_qb_version` key is in {#meta}, else `nil`.
627
+ #
628
+ def qb_requirement
629
+ if meta['requirements'] &&
630
+ meta['requirements']['gems'] &&
631
+ meta['requirements']['gems']['qb']
632
+ Gem::Requirement.new meta['requirements']['gems']['qb']
633
+ end
634
+ end
635
+
636
+
620
637
  # language inter-op
621
638
  # -----------------------------------------------------------------------
622
639
 
@@ -1,9 +1,79 @@
1
1
  module QB
2
+ # Constants
3
+ # =====================================================================
4
+
2
5
  GEM_NAME = 'qb'
3
6
 
4
- VERSION = "0.1.69"
7
+ VERSION = "0.1.70"
8
+
9
+ MIN_ANSIBLE_VERSION = Gem::Version.new '2.1.2'
10
+
11
+
12
+
13
+ # Class Methods
14
+ # =====================================================================
5
15
 
6
16
  def self.gemspec
7
17
  Gem.loaded_specs[GEM_NAME]
8
18
  end
9
- end
19
+
20
+
21
+ # Get the {Gem::Version} parse of {QB::VERSION}.
22
+ #
23
+ # @return [Gem::Version]
24
+ #
25
+ def self.gem_version
26
+ Gem::Version.new VERSION
27
+ end
28
+
29
+
30
+ # Check that the Ansible version is not less than {QB::MIN_ANSIBLE_VERSION}.
31
+ #
32
+ # @raise [QB::AnsibleVersionError]
33
+ # If the version of Ansible found is less than {QB::MIN_ANSIBLE_VERSION}.
34
+ #
35
+ def self.check_ansible_version
36
+ out = Cmds.out! 'ansible --version'
37
+ version_str = out[/ansible\ ([\d\.]+)/, 1]
38
+
39
+ if version_str.nil?
40
+ raise NRSER.dedent <<-END
41
+ could not parse ansible version from `ansible --version` output:
42
+
43
+ #{ out }
44
+ END
45
+ end
46
+
47
+ version = Gem::Version.new version_str
48
+
49
+ if version < QB::MIN_ANSIBLE_VERSION
50
+ raise QB::AnsibleVersionError, NRSER.squish(
51
+ <<-END
52
+ QB #{ QB::VERSION } requires Ansible #{ QB::MIN_ANSIBLE_VERSION },
53
+ found version #{ version_str } at #{ `which ansible` }
54
+ END
55
+ )
56
+ end
57
+ end # .check_ansible_version
58
+
59
+
60
+ # If `role` has a {QB::Role#qb_requirement} raise an error if this version of
61
+ # QB doesn't satisfy it.
62
+ #
63
+ # @raise [QB::QBVersionError]
64
+ # If this version of QB doesn't satisfy the role's requirements.
65
+ #
66
+ def self.check_qb_version role
67
+ unless role.qb_requirement.nil? ||
68
+ role.qb_requirement.satisfied_by?(QB.gem_version)
69
+ raise QB::QBVersionError, NRSER.squish(
70
+ <<-END
71
+ Role #{ role } requires QB #{ role.qb_requirement }, using QB
72
+ #{ QB.gem_version } from #{ QB::ROOT }.
73
+ END
74
+ )
75
+ end
76
+ end # .check_qb_version
77
+
78
+
79
+ end # module QB
@@ -7,6 +7,12 @@
7
7
  # description of the role to show in it's help output.
8
8
  description: null
9
9
 
10
+ # Gemspec-style requirements. Right now only `gems:qb` is used, but plan to
11
+ # generalize in the future.
12
+ requirements:
13
+ gems:
14
+ qb: ~> 0.1.69
15
+
10
16
  # prefix for role variables
11
17
  var_prefix: null
12
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.69
4
+ version: 0.1.70
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
@@ -181,6 +181,7 @@ files:
181
181
  - exe/qb
182
182
  - lib/qb.rb
183
183
  - lib/qb/ansible_module.rb
184
+ - lib/qb/errors.rb
184
185
  - lib/qb/options.rb
185
186
  - lib/qb/options/option.rb
186
187
  - lib/qb/package/version.rb