Commits

Chad Perrin committed 7cb97e1

it exists now

Comments (0)

Files changed (4)

+# Open Works License
+
+This is version 0.9.2 of the Open Works License.
+
+## Terms
+
+Permission is hereby granted by the copyright holder(s), author(s), and
+contributor(s) of this work, to any person who obtains a copy of this work in
+any form, to reproduce, modify, distribute, publish, sell, use, or otherwise
+deal in the licensed material without restriction, provided the following
+conditions are met:
+
+Redistributions, modified or unmodified, in whole or in part, must retain
+applicable copyright notices, the above license notice, these conditions, and
+the following disclaimer.
+
+NO WARRANTY OF ANY KIND IS IMPLIED BY, OR SHOULD BE INFERRED FROM, THIS LICENSE
+OR THE ACT OF DISTRIBUTION UNDER THE TERMS OF THIS LICENSE, INCLUDING BUT NOT
+LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE
+WORK, OR THE USE OF OR OTHER DEALINGS IN THE WORK.
+# Versionize
+
+I want simple version capabilities.  Here they are.
+
+## credits
+
+This program was written by Chad Perrin, Copyright 2012.  It can be
+redistributed under the terms of the Open Works License (see LICENSE file).
+More information about the OWL can be found at:
+
+    http://owl.apotheon.org

ruby/lib/versionize.rb

+=begin rdoc
+
+Versionize provides a simple version management and reporting interface for
+Ruby projects.  Include the Versionize module in your class, set the @version
+variable, and start using the version method.  Away you go.
+
+=end
+
+module Versionize
+  def self.included(base)
+    base.extend(ClassMethods)
+  end
+
+=begin
+
+The +@version" hash is the core of Versionize.  Set the values of the three
+sub-versions (+:major+, +:minor+, and +:revision+) to desired values.
+
+=end
+
+  @version = {
+    :major      =>  0,
+    :minor      =>  0,
+    :revision   =>  1
+  }
+
+  module ClassMethods
+
+=begin
+
+The +version+ method takes one optional argument +format+, indicating the type
+of data you want the method to return (+:array+, +:hash+, or +:string+).  The
+default format is +:string+.  The return value includes all three sub-versions.
+
+Examples:
+
+        Versionize.version
+        => "0.0.1"
+
+        Versionize.version(:array)
+        => [0,0,1]
+
+        Versionize.version(:hash)
+        => {:major=>0,:minor=>0,:revision=>1}
+
+=end
+
+    def version(format=:string)
+      case format
+      when :array
+        [ @version[:major], @version[:minor], @version[:revision] ]
+      when :hash
+        @version
+      when :string
+        version(:array).collect {|n| n.to_s }.join '.'
+      end
+    end
+
+=begin
+
+The +major+ method takes one optional argument +format+, indicating the type of
+data you want the method to return (+:integer+ or +:string+).  The default
+format is +:integer+.  The return value includes only the +:major+ sub-version.
+
+Examples:
+
+        Versionize.major
+        => 0
+
+        Versionize.major(:string)
+        => "0"
+
+=end
+
+    def major(format=:integer)
+      case format
+      when :integer
+        @version[:major]
+      when :string
+        @version[:major].to_s
+      end
+    end
+
+=begin
+
+The +minor+ method operates just like the +major+ method except that its return
+value includes only the +:minor+ sub-version.
+
+=end
+
+    def minor(format=:integer)
+      case format
+      when :integer
+        @version[:minor]
+      when :string
+        @version[:minor].to_s
+      end
+    end
+
+=begin
+
+The +revision+ method operates just like the +major+ method except that its
+return value includes only the +:revision+ sub-version.
+
+=end
+
+    def revision(format=:integer)
+      case format
+      when :integer
+        @version[:revision]
+      when :string
+        @version[:revision].to_s
+      end
+    end
+  end
+
+  extend ClassMethods
+end

ruby/versionize.gemspec

+load 'lib/versionize.rb'
+
+Gem::Specification.new do |s|
+  s.name            =   'versionize'
+  s.version         =   Versionize.version
+  s.authors         =   ['Chad Perrin']
+  s.date            =   '2012-10-23'
+  s.description     =   <<-EOF
+    Versionize exists to provide simple version management and reporting.
+  EOF
+  s.summary         =   'Versionize - simple software versions'
+  s.email           =   'code@apotheon.net'
+  s.files           =   [
+    'LICENSE',
+    'README.md',
+    'lib/versionize.rb'
+  ]
+  s.homepage        =   'http://versionize.fossrec.com'
+  s.has_rdoc        =   'true'
+  s.license         =   'OWL'
+
+  s.post_install_message    = <<-EOF
+    Thank you for using Versionize.  See the rdoc for details.
+  EOF
+end