versionate 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e31d4b61429a3510f9670c7fac0867ba74174a3c
4
- data.tar.gz: 1b41cf0a17ae9ab03eaba0fce88e3a0a69421904
3
+ metadata.gz: 94e6a72320c0db01b6e702717d6de8d645203dfd
4
+ data.tar.gz: cef7b4f819ac70cf7b2b12ed661a0cb9d160ba3f
5
5
  SHA512:
6
- metadata.gz: 1aaaf9ed9a1ab60625a880849fc1d34ddcee77305fc22d01cf8787a8515678391e130ca40f1db1c0f26de287044ead3f631dd4c2625b62e85229ac885c0e72b2
7
- data.tar.gz: 288d298676254781fe08350bb7a4d971567422c2ee243a811214307a81a164f9aa73e2dbb18c0ca3d80acceb6ed852b005227dce5dfcaff61c507ed0789b2107
6
+ metadata.gz: 2325185701938205d5ae1833b70e35980b55c265627b7cacefade5eec66429fc2cc087897ed28a55a7a43360c0089968382e6020c40759fb3d91b95700df40fe
7
+ data.tar.gz: ed9468e6b9564db667f74436ab68ba1fcfc28988eb9b712c413fbd98af99c7e2d91774c37cc8615da2d02ad1d46e07b3e7d52c34986aa885ec5b2e1686c69da4
data/README.md CHANGED
@@ -16,8 +16,57 @@ $ versionate
16
16
  ```
17
17
 
18
18
  If, for some odd reason, your Gemfile is called something other than “Gemfile”,
19
- you can specify the name as an argument to the command, like this:
19
+ you can specify the name as an argument to the sub-command `version`, like this:
20
20
 
21
21
  ```bash
22
- $ versionate file_with_gems.rb
22
+ $ versionate version file_with_gems.rb
23
+ ```
24
+
25
+ ### Options
26
+
27
+ You can tweak the output of versionate by passing in some options to the
28
+ command. First off, it's simple to strip off the patch versions in the resulting
29
+ versions by passing in the `--no-patch` flag:
30
+
31
+ ```bash
32
+ $ versionate --no-patch
33
+ ```
34
+
35
+ Prepending a version specifier to the version is simple as well, just pass it in
36
+ to the `--specifier` option:
37
+
38
+ ```bash
39
+ $ versionate --specifier="~>"
40
+ ```
41
+
42
+ Of course, this also works when using the more verbose syntax:
43
+
44
+ ```bash
45
+ $ versionate version --no-patch --specifier="~>" Gemfile
46
+ ```
47
+
48
+ ### Getting help
49
+
50
+ If you find yourself forgetting commands and/or options the `help` sub-command
51
+ is always available for you:
52
+
53
+ ```bash
54
+ $ versionate help
55
+ Commands:
56
+ versionate help [COMMAND] # Describe available commands or one specific command
57
+ versionate process [FILENAME] # Processes a given file (default: Gemfile)
58
+ ```
59
+
60
+ You can also ask for help on specific sub-command:
61
+
62
+ ```bash
63
+ $ versionate help process
64
+ Usage:
65
+ versionate process [FILENAME]
66
+
67
+ Options:
68
+ [--patch], [--no-patch] # Whether or not to keep patch version (default: true)
69
+ [--specifier=SPECIFIER] # Specifier to be prepended to version
70
+
71
+ Processes a given file (default: Gemfile)
23
72
  ```
data/bin/versionate CHANGED
@@ -1,9 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- require "versionate"
3
+ require "versionate/cli"
4
4
 
5
- if ARGV.any?
6
- Versionate.versionate ARGV.first
7
- else
8
- Versionate.versionate
9
- end
5
+ Versionate::CLI.start ARGV
@@ -0,0 +1,31 @@
1
+ require "thor"
2
+
3
+ require "versionate"
4
+
5
+ module Versionate
6
+ class CLI < Thor
7
+ DEFAULT_GEMFILE_NAME = "Gemfile"
8
+
9
+ desc "process [FILENAME]", "Processes a given file (default: Gemfile)"
10
+
11
+ option :patch,
12
+ type: :boolean,
13
+ desc: "Whether or not to keep patch version (default: true)"
14
+
15
+ option :specifier,
16
+ type: :string,
17
+ desc: "Specifier to be prepended to version"
18
+ def process(file = DEFAULT_GEMFILE_NAME)
19
+ Versionate.versionate file, options
20
+ end
21
+
22
+ desc "version", "Display the version of versionate"
23
+
24
+ def version
25
+ puts Versionate::VERSION
26
+ end
27
+
28
+ default_task :process
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Versionate
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,9 +1,10 @@
1
1
  module Versionate
2
2
  class Versioner
3
- GEM_REGEXP = /^\s*gem ['"](?<name>.+?)['"](?<extra>,.+$?)?/
3
+ GEM_REGEXP = /^\s*gem ['"](?<name>.+?)['"](?<extra>,.+$?)?/
4
+ VERSION_REGEXP = /^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/
4
5
 
5
- def versionate(filename)
6
- result = process filename
6
+ def versionate(filename, options = {})
7
+ result = process filename, options
7
8
 
8
9
  File.open filename, "w" do |file|
9
10
  file.write result
@@ -14,7 +15,10 @@ module Versionate
14
15
  provider.info(gem_name.to_sym)["version"]
15
16
  end
16
17
 
17
- def process(filename)
18
+ def process(filename, options = {})
19
+ patch = options.fetch("patch", true)
20
+ specifier = options["specifier"]
21
+
18
22
  orig_file = File.open(filename)
19
23
  tmp = StringIO.new
20
24
 
@@ -23,6 +27,10 @@ module Versionate
23
27
 
24
28
  if gem_name
25
29
  version = latest_version_for gem_name
30
+
31
+ version = remove_patch_version version unless patch
32
+ version = with_specifier(specifier, version) if specifier
33
+
26
34
  tmp.puts "#{line.chomp}, '#{version}'"
27
35
  else
28
36
  tmp.puts line
@@ -52,5 +60,15 @@ module Versionate
52
60
  def provider
53
61
  @provider ||= ApiAdapter.new.provider
54
62
  end
63
+
64
+ def remove_patch_version(version)
65
+ version.match VERSION_REGEXP do |match|
66
+ [ match[:major], match[:minor] ].join "."
67
+ end
68
+ end
69
+
70
+ def with_specifier(specifier, version)
71
+ "#{specifier} #{version}"
72
+ end
55
73
  end
56
74
  end
data/lib/versionate.rb CHANGED
@@ -7,8 +7,8 @@ module Versionate
7
7
 
8
8
  class << self
9
9
 
10
- def versionate gemfile = "Gemfile"
11
- versioner.versionate gemfile
10
+ def versionate(gemfile, options)
11
+ versioner.versionate gemfile, options
12
12
  end
13
13
 
14
14
  def configure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versionate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sindre Moen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2014-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gems
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: coveralls
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +107,7 @@ files:
93
107
  - bin/versionate
94
108
  - lib/versionate.rb
95
109
  - lib/versionate/api_adapter.rb
110
+ - lib/versionate/cli.rb
96
111
  - lib/versionate/configuration.rb
97
112
  - lib/versionate/version.rb
98
113
  - lib/versionate/versioner.rb