qb 0.1.63 → 0.1.64

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
  SHA1:
3
- metadata.gz: 1ef09e66c557199b31f1fa7725791ca7d85578c7
4
- data.tar.gz: 56480bf1eecc3e6782681161fea75d5c44f07cc5
3
+ metadata.gz: c20bbb470860d5f8893a0b231f578aad308aa192
4
+ data.tar.gz: 6c3049e6fec28c454002d47feacc9148022ab1b1
5
5
  SHA512:
6
- metadata.gz: 7abb2dfc2004d47864ef78d19a45a9b87b8a0068b17fc8824afb7c3a06a64fc2553528b8b4f6f4079fb10f8fdb25d76be0be1082be7cfa41132a846ab11d2b27
7
- data.tar.gz: 3733e0018bd5a06cc2a8d8f2e83aa8bf9524bd1ef1b0eb87405e0aefe67eded5535d5e441c71eea1e0ec799ec052b246d58c14ad2a4ff9c0071239623fbf4ad4
6
+ metadata.gz: 6406952deeec382082b5234ec5a2f75a7afd21e2a05626a1f67efbeab29d823e96e814356e2d607d8ec47367cca04fdab6189bc21d0ef78d41fa516953bf269c
7
+ data.tar.gz: 8537a944f35e7337a0aeb3dd1df7fec6c6446d913b8f1e5d4354d71c3863ce507cbb3ed797edb4fff07fa1825ac5a5366f9a7919bf87148a49204f160ca29f21
data/lib/qb/options.rb CHANGED
@@ -2,6 +2,7 @@ require 'optparse'
2
2
 
3
3
  require_relative "role/errors"
4
4
  require_relative "options/option"
5
+ require 'qb/package/version'
5
6
 
6
7
  module QB
7
8
  class Options
@@ -133,6 +134,8 @@ module QB
133
134
  Array
134
135
  when 'integer', 'int'
135
136
  Integer
137
+ when 'version'
138
+ QB::Package::Version
136
139
  when Hash
137
140
  if option.meta['type'].key? 'one_of'
138
141
  klass = Class.new
@@ -274,6 +277,10 @@ module QB
274
277
  end
275
278
 
276
279
  opt_parser = OptionParser.new do |opts|
280
+ opts.accept(QB::Package::Version) do |string|
281
+ QB::Package::Version.from_string(string).to_h
282
+ end
283
+
277
284
  opts.banner = @role.banner
278
285
 
279
286
  opts.on(
@@ -38,7 +38,10 @@ module QB
38
38
  Options.cli_ize_name "#{ @include_path.join('-') }-#{ @meta_name }"
39
39
  end
40
40
 
41
- @var_name = if role.var_prefix
41
+ @var_name = if @meta['var_name']
42
+ # prefer an explicit, exact variable name if provided
43
+ @meta['var_name']
44
+ elsif role.var_prefix
42
45
  Options.var_ize_name "#{ role.var_prefix }_#{ @meta_name }"
43
46
  else
44
47
  Options.var_ize_name @meta_name
@@ -0,0 +1,80 @@
1
+ module QB
2
+ module Package
3
+ # An attempt to unify NPM and Gem version schemes to a reasonable extend,
4
+ # and hopefully cover whatever else the cat may drag in.
5
+ class Version
6
+ # Create a Version instance from a Gem::Version
7
+ def self.from_gem_version version
8
+ release_segments = version.segments.take_while {|seg| !seg.is_a?(String)}
9
+ prerelease_segments = version.segments[release_segments.length..-1]
10
+
11
+ new raw: version.to_s,
12
+ major: release_segments[0],
13
+ minor: release_segments[1],
14
+ patch: release_segments[2],
15
+ prerelease: prerelease_segments,
16
+ build: [],
17
+ release: version.release.to_s
18
+ end
19
+
20
+ def self.from_npm_version version
21
+ stmt = NRSER.squish <<-END
22
+ var Semver = require('semver');
23
+
24
+ console.log(
25
+ JSON.stringify(
26
+ Semver(#{ JSON.dump version })
27
+ )
28
+ );
29
+ END
30
+
31
+ parse = JSON.load Cmds.out!("node --eval %s", stmt)
32
+
33
+ new raw: version,
34
+ major: parse['major'],
35
+ minor: parse['minor'],
36
+ patch: parse['patch'],
37
+ prerelease: parse['prerelease'],
38
+ build: parse['build'],
39
+ release: [parse['major'], parse['minor'], parse['patch']].join(".")
40
+ end
41
+
42
+ def self.from_string string
43
+ if string.include? '-'
44
+ self.from_npm_version string
45
+ else
46
+ self.from_gem_version Gem::Version.new(string)
47
+ end
48
+ end
49
+
50
+ # Construct a new Version
51
+ def initialize raw:, major:, minor:, patch:, prerelease:, build:, release:
52
+ @raw = raw
53
+ @major = major
54
+ @minor = minor
55
+ @patch = patch
56
+ @prerelease = prerelease
57
+ @build = build
58
+ @release = release
59
+
60
+ @level = @prerelease[0] || 'release'
61
+
62
+ @is_release = @prerelease.empty?
63
+ @is_dev = @prerelease[0] == 'dev'
64
+ @is_rc = @prerelease[0] == 'rc'
65
+ end
66
+
67
+ # dump all instance variables into a hash
68
+ def to_h
69
+ instance_variables.map {|var|
70
+ [var[1..-1], instance_variable_get(var)]
71
+ }.to_h
72
+ end # #to_h
73
+
74
+ # Dump all instance variables in JSON serialization
75
+ def to_json *args
76
+ to_h.to_json *args
77
+ end
78
+ end
79
+ end # Package
80
+ end # QB
data/lib/qb/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module QB
2
2
  GEM_NAME = 'qb'
3
3
 
4
- VERSION = "0.1.63"
4
+ VERSION = "0.1.64"
5
5
 
6
6
  def self.gemspec
7
7
  Gem.loaded_specs[GEM_NAME]
data/library/path_facts CHANGED
@@ -14,6 +14,7 @@ end
14
14
  require 'ostruct'
15
15
 
16
16
  require 'qb'
17
+ require 'qb/package/version'
17
18
  require 'cmds'
18
19
  require 'pathname'
19
20
  require 'uri'
@@ -28,70 +29,6 @@ end
28
29
  GITHUB_SSH_URL_RE = /^git@github\.com\:(?<owner>.*)\/(?<name>.*)\.git$/
29
30
  GITHUB_HTTPS_URL_RE = /^https:\/\/github\.com\/(?<owner>.*)\/(?<name>.*)\.git$/
30
31
 
31
- # An attempt to unify NPM and Gem version schemes to a reasonable extend,
32
- # and hopefully cover whatever else the cat may drag in.
33
- class Version
34
- # Create a Version instance from a Gem::Version
35
- def self.from_gem_version version
36
- release_segments = version.segments.take_while {|seg| !seg.is_a?(String)}
37
- prerelease_segments = version.segments[release_segments.length..-1]
38
-
39
- new raw: version.to_s,
40
- major: release_segments[0],
41
- minor: release_segments[1],
42
- patch: release_segments[2],
43
- prerelease: prerelease_segments,
44
- build: [],
45
- release: version.release
46
- end
47
-
48
- def self.from_npm_version version
49
- stmt = NRSER.squish <<-END
50
- var Semver = require('semver');
51
-
52
- console.log(
53
- JSON.stringify(
54
- Semver(#{ JSON.dump version })
55
- )
56
- );
57
- END
58
-
59
- parse = JSON.load Cmds.out!("node --eval %s", stmt)
60
-
61
- new raw: version,
62
- major: parse['major'],
63
- minor: parse['minor'],
64
- patch: parse['patch'],
65
- prerelease: parse['prerelease'],
66
- build: parse['build'],
67
- release: [parse['major'], parse['minor'], parse['patch']].join(".")
68
- end
69
-
70
- # Construct a new Version
71
- def initialize raw:, major:, minor:, patch:, prerelease:, build:, release:
72
- @raw = raw
73
- @major = major
74
- @minor = minor
75
- @patch = patch
76
- @prerelease = prerelease
77
- @build = build
78
- @release = release
79
-
80
- @level = @prerelease[0] || 'release'
81
-
82
- @is_release = @prerelease.empty?
83
- @is_dev = @prerelease[0] == 'dev'
84
- @is_rc = @prerelease[0] == 'rc'
85
- end
86
-
87
- # Dump all instance variables in JSON serialization
88
- def to_json *args
89
- instance_variables.map {|var|
90
- [var[1..-1].to_sym, instance_variable_get(var)]
91
- }.to_h.to_json *args
92
- end
93
- end
94
-
95
32
  class PathFacts < QB::AnsibleModule
96
33
  # Add a bunch of useful things to know about the path
97
34
  def add_path_facts
@@ -225,7 +162,7 @@ class PathFacts < QB::AnsibleModule
225
162
 
226
163
  spec = Gem::Specification::load(gemspec_path.to_s)
227
164
  gem.name = spec.name
228
- gem.version = Version.from_gem_version spec.version
165
+ gem.version = QB::Package::Version.from_gem_version spec.version
229
166
  end
230
167
 
231
168
  # Add facts about an NPM package based in `@path`, if any.
@@ -246,7 +183,10 @@ class PathFacts < QB::AnsibleModule
246
183
 
247
184
  # To stay consistent with Gem
248
185
  npm.name = npm.package_json['name']
249
- npm.version = Version.from_npm_version npm.package_json['version']
186
+
187
+ npm.version = QB::Package::Version.from_npm_version(
188
+ npm.package_json['version']
189
+ )
250
190
  end
251
191
 
252
192
  # Run the module.
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.63
4
+ version: 0.1.64
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
@@ -183,6 +183,7 @@ files:
183
183
  - lib/qb/ansible_module.rb
184
184
  - lib/qb/options.rb
185
185
  - lib/qb/options/option.rb
186
+ - lib/qb/package/version.rb
186
187
  - lib/qb/role.rb
187
188
  - lib/qb/role/errors.rb
188
189
  - lib/qb/util.rb