dated_version 2008.07.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env rake
2
+ require 'rubygems' unless defined?(Gem)
3
+ require 'rake' unless defined?(Rake)
4
+
5
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
6
+ $:.uniq!
7
+ require 'dated_version'
8
+
9
+ # TODO : make some actual rake tasks instead!
10
+ def load_dated_version(file)
11
+ ver = Class.new.class_eval(File::read(file))
12
+ DatedVersion.new(ver::MAJOR, ver::MINOR, (ENV['TINY_VERSION'] || ver::TINY))
13
+ rescue
14
+ DatedVersion.new(ENV['TINY_VERSION'])
15
+ end
16
+
17
+ Package = false # Build zips and tarballs?
18
+
19
+ GSpec = Gem::Specification.new do |s|
20
+ s.name = 'dated_version'
21
+ s.summary = 'A simple to use version class based on a date and iterative tiny version.'
22
+ s.description = s.summary
23
+ s.author = 'James Tucker'
24
+ s.email = 'raggi@rubyforge.org'
25
+ s.homepage = 'http://github.com/raggi/dated_version'
26
+ s.rubyforge_project = nil
27
+
28
+ s.version = load_dated_version('lib/dated_version/version.rb').to_s
29
+
30
+ s.files = %w(Rakefile) + Dir.glob("{bin,docs,lib,spec,test,scripts,tasks}/**/*")
31
+
32
+ if s.has_rdoc = true
33
+ main_rdoc = "README" if test ?e, "README"
34
+ main_rdoc ||= "docs/README" if test ?e, "docs/README"
35
+ s.extra_rdoc_files = Dir.glob("docs/*")
36
+ s.rdoc_options.concat %W(
37
+ --title #{s.name}
38
+ --main #{main_rdoc}
39
+ --tab-width 2
40
+ --line-numbers
41
+ --inline-source
42
+ --charset utf-8
43
+ )
44
+ end
45
+
46
+ s.bindir = 'bin' if File.directory?('bin')
47
+ s.require_path = 'lib'
48
+
49
+ s.platform = Gem::Platform::RUBY
50
+ if runner = Dir['{spec,test}/runner'].first
51
+ s.test_file = runner
52
+ end
53
+ end
54
+
55
+ task :reversion do
56
+ v = load_dated_version('lib/dated_version/version.rb').succ
57
+ open('lib/dated_version/version.rb', 'w') do |f|
58
+ f.write v.to_ruby_code('DatedVersion', 'class')
59
+ end
60
+ end
61
+
62
+ task :release => [:test, :reversion, :gem]
63
+
64
+ task :clean do
65
+ rm_f 'lib/dated_version/version.rb'
66
+ end
67
+
68
+ Dir.glob('tasks/**/*.rake').each { |r| Rake.application.add_import r }
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008 James Tucker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ = Dated Version
2
+
3
+ Please see the DatedVersion class docs for full usage examples.
4
+
5
+ == Summary
6
+
7
+ A simple yet effective (and easy!) version class abstracted from dates.
8
+
9
+ == Key features
10
+
11
+ Really, see the class docs, but:
12
+ * Simple to create, just make a new one.
13
+ * Simple to adjust for tiny versions, just supply the tiny value to new.
14
+ * Simple to create other versions, just supply strings or arrays with all or
15
+ partial field values.
16
+ * Simple conversion to date, call #to_date.
17
+ * Simple re-representation as a newgem/hoe style version, see #to_constant.
18
+ * Simple string representation, and parsing.
19
+ * Simply Comparable!
20
+ * Simple, simple, simple, but just wide enough too :-)
21
+
22
+ == Rationale
23
+
24
+ These are thoughts! A date based version may not be for everyone.
25
+
26
+ The idiom is, version numbers seem to be settling on a general three value
27
+ set, however this adds a few stresses to the developer:
28
+ What defines a {major, minor, tiny} version? (the specific sense, for a
29
+ particular lib). It's totally undefined really.
30
+ There are some standard hand-wavy definitions of these things, but they only
31
+ leave more 'in this case' questions. I regularly had issues with the answers
32
+ to these definitions.
33
+
34
+ When you're starting a project, and no real maintenance cycle is required (the
35
+ versions just go up), then there's no issue anyway, so early on, people don't
36
+ care.
37
+
38
+ When you're doing maintenance work and refactor changes alter edge cases or
39
+ trivial api changes create important semantic or stateful alterations, then
40
+ these versions become a real real pain. It becomes a religious or political
41
+ dispute as to minor vs major change and so on. About the only thing anyone
42
+ agrees on is that there should be a patchlevel, or 'maintenance level'.
43
+
44
+ The idea here is, simplify the whole middle range. If you have a released
45
+ version that needs maintenance, you iterate tiny, the maintenance value.
46
+ Nothing more. Changes should never occur to the API unless it's absolutely
47
+ suitable, e.g. fix for documentation.
48
+
49
+ Simple for the developer. Simple for the user.
50
+
51
+ == Notes
52
+
53
+ There is a to_constant function which provides a re-representation of the
54
+ DatedVersion as a three part MAJOR, MINOR, TINY set. The re-representation
55
+ tries to accomodate tiny and major with some level of sanity, by compacting
56
+ the month and day into a year day. It is important to note that if used
57
+ consistently, this is a valid representation of the DatedVersion. If however
58
+ an attempt to compare the two representations is made, this will fail badly
59
+ for many values.
60
+
61
+ == TODO
62
+ refactor out from specs.
63
+ finish specs
64
+ add rake helpers
@@ -0,0 +1,72 @@
1
+ class BasicVersion
2
+ Fields = :major, :minor, :tiny
3
+ GlobString = (['*'] * Fields.size).join('.')
4
+ StringRexp = /#{(['(\d+)'] * Fields.size).join('\.')}/
5
+ attr_accessor(*Fields)
6
+
7
+ def initialize(*args)
8
+ if args.size == 1 && args.first.kind_of?(String) && md = StringRexp.match(args.first)
9
+ args = md.captures.map { |a| a.to_i }
10
+ end
11
+ case args.size
12
+ when 0
13
+ # no-op
14
+ when 1
15
+ self.tiny = args.first.to_i
16
+ when 3
17
+ self.major, self.minor, self.tiny = *args.map{|a| a.to_i }
18
+ else
19
+ raise ArgumentError
20
+ end
21
+ Fields.each_with_index do |f, i|
22
+ next unless self.send(f).nil?
23
+ self.send(:"#{f}=", 0)
24
+ end
25
+ end
26
+
27
+ def to_a
28
+ [self.major, self.minor, self.tiny]
29
+ end
30
+
31
+ def to_s
32
+ "%d.%d.%d" % to_a
33
+ end
34
+
35
+ def to_ruby_constants
36
+ <<-EORUBY
37
+ MAJOR = #{self.major}
38
+ MINOR = #{self.minor}
39
+ TINY = #{self.tiny}
40
+ STRING = #{to_s.inspect}
41
+ EORUBY
42
+ end
43
+
44
+ def to_ruby_code(module_name = 'AppVersion', namespace_type = 'module')
45
+ <<-EORUBY
46
+ #{namespace_type} #{module_name}
47
+ module VERSION
48
+ #{to_ruby_constants.strip}
49
+ self
50
+ end
51
+ end
52
+ EORUBY
53
+ end
54
+
55
+ include Comparable
56
+
57
+ def succ
58
+ self.class.new(self.major, self.minor, self.tiny + 1)
59
+ end
60
+
61
+ def <=>(other)
62
+ v = 0
63
+ Fields.each do |f|
64
+ return v unless other.respond_to?(f)
65
+ v = self.send(f) <=> other.send(f)
66
+ return v unless v == 0
67
+ end
68
+ v
69
+ end
70
+ end
71
+
72
+ (require 'raggi/irb/drop'; dROP!(binding)) if __FILE__ == $0
@@ -0,0 +1,20 @@
1
+ # See DatedVersion.
2
+ require 'date'
3
+ require File.dirname(__FILE__) + '/basic_version.rb'
4
+ # = Dated Version
5
+ class DatedVersion < BasicVersion
6
+ alias year major
7
+ alias year= major=
8
+ alias month minor
9
+ alias month= minor=
10
+
11
+ def initialize(*args)
12
+ t = Time.now
13
+ self.year, self.month = t.year, t.month
14
+ super
15
+ end
16
+
17
+ def to_s
18
+ "%04d.%02d.%d" % to_a
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # Disable test/unit and rspec from running, in case loaded by broken tools.
2
+ Test::Unit.run = false if defined?(Test::Unit)
3
+ Spec::run = false if defined?(Spec) && Spec::respond_to?(:run=)
4
+
5
+ # Setup a nice testing environment
6
+ $TESTING=true
7
+ $:.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $:.uniq!
9
+ %w[rubygems facon bacon].each { |r| require r }
10
+
11
+ # Bacon doesn't do any automagic, so lets tell it to!
12
+ Bacon.summary_on_exit
13
+
14
+ require 'dated_version'
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ __DIR__ = File.dirname(__FILE__)
3
+ __APP__ = File.expand_path(__DIR__ + '/../')
4
+
5
+ puts
6
+ Dir.chdir(__APP__) do
7
+ files = ARGV.empty? ? Dir.glob('{test,spec}/**/{test,spec}_*.rb') : ARGV
8
+ files.each { |f| require f }
9
+ end
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ describe 'dated version' do
4
+
5
+ should 'default to today with tiny version 0' do
6
+ v = DatedVersion.new
7
+ t = Time.now
8
+ v.year.should.eql(t.year)
9
+ v.month.should.eql(t.month)
10
+ v.tiny.should.eql(0)
11
+ end
12
+
13
+ should 'allow for customised tiny versions' do
14
+ t = 12
15
+ v = DatedVersion.new(t)
16
+ v.tiny.should.eql(t)
17
+ end
18
+
19
+ should 'parse strings as the first argument' do
20
+ str = 'v2008.7.1'
21
+ v = DatedVersion.new(str)
22
+ v.major.should.eql(2008)
23
+ v.minor.should.eql(7)
24
+ v.tiny.should.eql(1)
25
+ end
26
+
27
+ should 'implement to_a, in order year month tiny' do
28
+ t = Time.now
29
+ v = DatedVersion.new
30
+ v.to_a.should.eql([t.year, t.month, 0])
31
+ end
32
+
33
+ should 'allow full custom versions' do
34
+ year, month, tiny = 1, 2, 3
35
+ v = DatedVersion.new(year, month, tiny)
36
+ v.year.should.eql(year)
37
+ v.month.should.eql(month)
38
+ v.tiny.should.eql(tiny)
39
+ end
40
+
41
+ should 'present a padded string' do
42
+ year, month, tiny = 1, 2, 3
43
+ string = "0001.02.3"
44
+ v = DatedVersion.new(year, month, tiny)
45
+ v.to_s.should.eql(string)
46
+ end
47
+
48
+ should 'generate hoe like version code' do
49
+ year, month, tiny = 1, 2, 3
50
+ string = "0001.02.3"
51
+ v = DatedVersion.new(year, month, tiny)
52
+ mk = Class.new
53
+ mk.class_eval v.to_ruby_constants
54
+ mk::MAJOR.should.eql(year)
55
+ mk::MINOR.should.eql(month)
56
+ mk::TINY.should.eql(tiny)
57
+ mk::STRING.should.eql(string)
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ # Poor mans autotest, for when you absolutely positively, just need an autotest.
2
+ # N.B. Uses a runner under test/ or spec/, so you can customize the runtime.
3
+ # Thanks to manveru for this!
4
+ desc "Run specs every time a file changes in lib or spec"
5
+ task :autospec do
6
+ rb = Gem.ruby rescue nil
7
+ rb ||= (require 'rbconfig'; File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']))
8
+ command = 'spec/runner' if test ?e, 'spec/runner'
9
+ command ||= 'test/runner' if test ?e, 'test/runner'
10
+ files = Dir.glob('{lib,spec,test}/**/*.rb')
11
+ mtimes = {}
12
+ sigtrap = proc { puts "\rDo that again, I dare you!"; trap(:INT){ exit 0 }; sleep 0.8; trap(:INT, &sigtrap) }
13
+ trap(:INT, &sigtrap)
14
+ system "#{rb} -I#{GSpec.require_path} #{command}"
15
+ while file = files.shift
16
+ begin
17
+ mtime = File.mtime(file)
18
+ mtimes[file] ||= mtime
19
+ if mtime > mtimes[file]
20
+ files = Dir.glob('{lib,spec,test}/**/*.rb') - [file] # refresh the file list.
21
+ puts
22
+ system "#{rb} -I#{GSpec.require_path} #{command} #{file}"
23
+ puts
24
+ end
25
+ mtimes[file] = mtime
26
+ files << file
27
+ rescue Exception
28
+ retry
29
+ end
30
+ # print "\rChecking: #{file.ljust((ENV['COLUMNS']||80)-11)}";$stdout.flush
31
+ sleep 0.2
32
+ end
33
+ end
@@ -0,0 +1,108 @@
1
+ #
2
+ # = raggi's Rake Generic Tasks
3
+ #
4
+ # A generic rake task set, supporting several forms of testing environment,
5
+ # gem installs, and so on. Rides on top of a gem specification, and rake
6
+ # built-ins.
7
+ #
8
+ # You will need to define a GSpec method or object (constant scope) to pass
9
+ # back a gem specification for the project. Crufty rake tasks will be removed
10
+ # as you remove portions of the specification from your gemspec.
11
+ #
12
+ # Suggestions, fixes and additions always welcome.
13
+ #
14
+
15
+ require 'rubygems'
16
+ require 'rake/gempackagetask'
17
+ require 'rake/testtask'
18
+ require 'rake/rdoctask'
19
+ require 'rake/clean'
20
+
21
+ module FileUtils
22
+ # If any of these methods ever clobber, try removing them.
23
+ # Hopefully they'll do something semantically similar.
24
+ abort "Err: #{__FILE__}:#{__LINE__} monkey patch windows? clobbers!" unless instance_methods.grep(/windows\?/).empty?
25
+ abort "Err: #{__FILE__}:#{__LINE__} monkey patch sudo clobbers!" unless instance_methods.grep(/sudo/).empty?
26
+ abort "Err: #{__FILE__}:#{__LINE__} monkey patch gem_cmd clobbers!" unless instance_methods.grep(/gem_cmd/).empty?
27
+ def windows?; RUBY_PLATFORM =~ /mswin|mingw/; end
28
+ def sudo(cmd)
29
+ if windows? || (require 'etc'; Etc.getpwuid.uid == 0)
30
+ sh cmd
31
+ else
32
+ sh "sudo #{cmd}"
33
+ end
34
+ end
35
+ def gem_cmd(action, name, *args)
36
+ rb = Gem.ruby rescue nil
37
+ rb ||= (require 'rbconfig'; File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']))
38
+ sudo "#{rb} -r rubygems -e 'require %{rubygems/gem_runner}; Gem::GemRunner.new.run(%w{#{action} #{name} #{args.join(' ')}})'"
39
+ end
40
+ end
41
+
42
+ # Setup our packaging tasks, we're just jacking the builtins.
43
+ Rake::GemPackageTask.new(GSpec) do |pkg|
44
+ pkg.need_tar, pkg.need_tar_gz, pkg.need_zip = true, true, true if Package
45
+ pkg.gem_spec = GSpec
46
+ end
47
+ Rake::Task[:clobber].enhance [:clobber_package]
48
+
49
+ # Test tasks can be made up of spec files or test files, provided you require
50
+ # the right stuff in your test / spec helpers.
51
+ Rake::TestTask.new do |t|
52
+ t.libs = Array(GSpec.require_path || 'lib')
53
+ t.warning = true
54
+ t.pattern = '{spec,test}/**/*.rb'
55
+ end
56
+
57
+ # Use {test,spec}/runner for alternative spec framework runners & rubygems
58
+ # test runner file.
59
+ if runner = Dir['{spec,test}/runner'].first
60
+ desc "Run tests using #{runner}"
61
+ task :spec do ruby runner end
62
+ else
63
+ task :spec => :test # pass on to a generic test task!
64
+ end
65
+
66
+ # Only generate rdoc if the spec says so, again, jack the builtins.
67
+ if GSpec.has_rdoc
68
+ Rake::RDocTask.new do |rd|
69
+ rd.title = GSpec.name
70
+ rd.rdoc_dir = 'rdoc'
71
+ rd.main = "README" if test ?e, "README"
72
+ rd.main ||= "docs/README" if test ?e, "docs/README"
73
+ rd.rdoc_files.include("lib/**/*.rb", *GSpec.extra_rdoc_files)
74
+ end
75
+ Rake::Task[:clobber].enhance [:clobber_rdoc]
76
+
77
+ desc 'Generate and open documentation'
78
+ task :docs => :rdoc do
79
+ case RUBY_PLATFORM
80
+ when /darwin/ ; sh 'open rdoc/index.html'
81
+ when /mswin|mingw/ ; sh 'start rdoc\index.html'
82
+ else
83
+ sh 'firefox rdoc/index.html'
84
+ end
85
+ end
86
+ end
87
+
88
+ if GSpec.default_executable
89
+ desc "Run #{GSpec.default_executable}"
90
+ task :run do ruby File.join(GSpec.bindir, GSpec.default_executable) end
91
+ end
92
+
93
+ desc 'Install gem (and sudo if required)'
94
+ task :install => :package do
95
+ gem_cmd(:install, "pkg/#{GSpec.name}-#{GSpec.version}.gem")
96
+ end
97
+
98
+ desc 'Uninstall gem (and sudo if required)'
99
+ task :uninstall do
100
+ gem_cmd(:uninstall, "#{GSpec.name}")
101
+ end
102
+
103
+ # Find an scm's store directory, if we do, make a task to commit to it only
104
+ # after running all the tests (successfully).
105
+ if scm = %w(git svn bzr hg).find { |d| File.directory? ".#{d}" }
106
+ desc "Run tests then commit to #{scm}"
107
+ task :commit => :test do sh "#{scm} commit" end
108
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dated_version
3
+ version: !ruby/object:Gem::Version
4
+ version: 2008.07.0
5
+ platform: ruby
6
+ authors:
7
+ - James Tucker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-31 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A simple to use version class based on a date and iterative tiny version.
17
+ email: raggi@rubyforge.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - docs/LICENSE
24
+ - docs/README
25
+ files:
26
+ - Rakefile
27
+ - docs/LICENSE
28
+ - docs/README
29
+ - lib/basic_version.rb
30
+ - lib/dated_version
31
+ - lib/dated_version.rb
32
+ - spec/helper.rb
33
+ - spec/runner
34
+ - spec/spec_dated_version.rb
35
+ - tasks/raggi_rake_generic
36
+ - tasks/raggi_rake_generic/autospec.rake
37
+ - tasks/raggi_rake_generic/project.rake
38
+ has_rdoc: true
39
+ homepage: http://github.com/raggi/dated_version
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --title
43
+ - dated_version
44
+ - --main
45
+ - docs/README
46
+ - --tab-width
47
+ - "2"
48
+ - --line-numbers
49
+ - --inline-source
50
+ - --charset
51
+ - utf-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: A simple to use version class based on a date and iterative tiny version.
73
+ test_files:
74
+ - spec/runner