rdavila-version_master 0.1.1

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.
data/README ADDED
@@ -0,0 +1,41 @@
1
+ VersionMaster
2
+ =============
3
+
4
+ A silly little tool for managing app versions heavily inspired by http://github.com/toland/app_version.
5
+
6
+ How to use
7
+ ==========
8
+
9
+ The plugin will copy the file version.yml into the config directory when installed.
10
+
11
+ # config/version.yml
12
+ ---
13
+ major: 1
14
+ minor: 0
15
+ patch: 0
16
+
17
+ You can manage this manually or use the rake tasks below.
18
+
19
+ rake version:bump VER=patch # ==> Bumped version 1.0.0 --> 1.0.1
20
+ rake version:bump VER=minor # ==> Bumped version 1.0.1 --> 1.1.0
21
+ rake version:bump VER=major # ==> Bumped version 1.1.0 --> 2.0.0
22
+ rake version:bump # ==> Bumped version 2.0.0 --> 2.0.1
23
+ rake version:set VER=4.2.2 # ==> Changed version 2.0.1 --> 4.2.2
24
+ rake version # ==> Current version is 4.2.2
25
+
26
+ You can also use the Capistrano recipe below to update versions when deploying.
27
+
28
+ cap deploy:bump # Updates patch number and uploads version.yml to the server.
29
+ cap deploy:bump VER=minor # Updates minor version number and uploads version.yml to the server.
30
+
31
+ Use the constant APP_VERSION in your views or elsewhere to display the current version.
32
+
33
+ Example:
34
+ <p>My App v.<%=APP_VERSION%></p> # ==> <p>My App v.4.2.2</p>
35
+
36
+ Installation
37
+ ============
38
+
39
+ script/plugin install git://github.com/balvig/version_master.git
40
+
41
+ Copyright (c) 2009 Jens Jakob Balvig, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc 'Run the specs'
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
10
+ t.spec_files = FileList['spec/**/*_spec.rb']
11
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ major: 1
3
+ minor: 0
4
+ patch: 0
@@ -0,0 +1,52 @@
1
+ module VersionMaster
2
+ class Version
3
+
4
+ DEFAULT_YAML_FILE_PATH = "#{RAILS_ROOT}/config/version.yml"
5
+
6
+ def initialize(yaml_file_path=DEFAULT_YAML_FILE_PATH)
7
+ @yaml_file_path = yaml_file_path
8
+ @parts ||= YAML.load(File.read(@yaml_file_path)).symbolize_keys
9
+ end
10
+
11
+ def bump(ver= :patch)
12
+ ver = ver.to_sym
13
+ @parts[ver] += 1
14
+ if ver == :minor
15
+ @parts[:patch] = 0
16
+ if @parts[:minor] >= 10
17
+ @parts[:major] += 1
18
+ @parts[:minor] = 0
19
+ end
20
+ elsif ver == :major
21
+ @parts[:minor] = @parts[:patch] = 0
22
+ end
23
+ save
24
+ end
25
+
26
+ def set(new_version)
27
+ @parts[:major], @parts[:minor], @parts[:patch] = new_version.split('.').collect(&:to_i)
28
+ save
29
+ end
30
+
31
+ def to_s
32
+ "#{major}.#{minor}.#{patch}"
33
+ end
34
+
35
+ def method_missing(method, *args)
36
+ if [:major,:minor,:patch].include?(method)
37
+ @parts[method]
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def save
46
+ File.open(@yaml_file_path, 'w') {|f| f.write(@parts.to_yaml) }
47
+ to_s
48
+ end
49
+ end
50
+ end
51
+
52
+ APP_VERSION = VersionMaster::Version.new.to_s
@@ -0,0 +1,28 @@
1
+ namespace :deploy do
2
+
3
+ desc "Bump version number and deploy"
4
+ task :bump do
5
+ version.bump
6
+ update_code
7
+ symlink
8
+ restart
9
+ end
10
+
11
+ namespace :version do
12
+
13
+ desc "Bump version number"
14
+ task :bump do
15
+ rake_params = ENV['VER'] ? "VER=#{ENV['VER']}" : ''
16
+ system "rake version:bump #{rake_params}"
17
+ end
18
+
19
+ desc "Upload version config file"
20
+ task :upload_config do
21
+ VERSION_FILE_PATH = 'config/version.yml'
22
+ top.upload VERSION_FILE_PATH, "#{release_path}/#{VERSION_FILE_PATH}"
23
+ end
24
+ end
25
+
26
+ after 'deploy:update_code', 'deploy:version:upload_config'
27
+
28
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 0
4
+ :patch: 0
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,8 @@
1
+ begin
2
+ require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
3
+ rescue LoadError
4
+ puts "You need to install rspec in your base app"
5
+ exit
6
+ end
7
+
8
+ plugin_spec_dir = File.dirname(__FILE__)
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/version.yml'
4
+
5
+ describe VersionMaster::Version do
6
+
7
+ before(:each) do
8
+ @version = VersionMaster::Version.new(FIXTURE_PATH)
9
+ end
10
+ after(:each) do
11
+ @version.set('1.0.0')
12
+ end
13
+
14
+ it "should load version data from yaml file" do
15
+ @version.to_s.should == '1.0.0'
16
+ end
17
+
18
+ describe "set" do
19
+ it "should set the version number" do
20
+ @version.set('3.4.2')
21
+ @version.to_s.should == '3.4.2'
22
+ end
23
+ end
24
+
25
+ describe "bump" do
26
+ it "should increment versions" do
27
+ @version.bump(:major)
28
+ @version.to_s.should == '2.0.0'
29
+
30
+ @version.bump(:minor)
31
+ @version.to_s.should == '2.1.0'
32
+
33
+ @version.bump(:patch)
34
+ @version.to_s.should == '2.1.1'
35
+
36
+ @version.bump
37
+ @version.to_s.should == '2.1.2'
38
+ end
39
+
40
+ it "should reset lesser versions" do
41
+ @version.bump(:patch)
42
+ @version.to_s.should == '1.0.1'
43
+
44
+ @version.bump(:minor)
45
+ @version.to_s.should == '1.1.0'
46
+
47
+ @version.bump(:major)
48
+ @version.to_s.should == '2.0.0'
49
+ end
50
+
51
+ it "should rollover minor to major" do
52
+ @version.set('2.9.0')
53
+ end
54
+ end
55
+
56
+ describe "save" do
57
+ it "should save version data to yaml file" do
58
+ @version.set('3.4.7')
59
+ VersionMaster::Version.new(FIXTURE_PATH).to_s.should == '3.4.7'
60
+ end
61
+ end
62
+
63
+
64
+ end
@@ -0,0 +1,19 @@
1
+ desc "Displays current version"
2
+ task :version => :environment do
3
+ puts "Current version is #{VersionMaster::Version.new.to_s}"
4
+ end
5
+
6
+ namespace :version do
7
+ desc "Bump version number"
8
+ task :bump => :environment do
9
+ version = VersionMaster::Version.new
10
+ puts "Bumped version #{version.to_s} --> #{ENV['VER'] ? version.bump(ENV['VER']) : version.bump}"
11
+ end
12
+
13
+ desc "Set version number"
14
+ task :set => :environment do
15
+ version = VersionMaster::Version.new
16
+ puts "Changed version #{version.to_s} --> #{version.set(ENV['VER'])}"
17
+ end
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdavila-version_master
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Jens Jakob Balvig
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-27 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " A simple Rails plugin for managing app versions.\n"
22
+ email: rdavila84@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - Rakefile
31
+ - README
32
+ - lib/version_master.rb
33
+ - lib/config/version.yml
34
+ - recipes/version_master.rb
35
+ - spec/fixtures/version.yml
36
+ - spec/spec.opts
37
+ - spec/version_master_spec.rb
38
+ - spec/spec_helper.rb
39
+ - tasks/version_master_tasks.rake
40
+ has_rdoc: true
41
+ homepage: http://github.com/balvig/version_master
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.6
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A simple Rails plugin for managing app versions.
70
+ test_files: []
71
+