Skip to content

Instantly share code, notes, and snippets.

@ericgj
Created September 14, 2011 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericgj/1215719 to your computer and use it in GitHub Desktop.
Save ericgj/1215719 to your computer and use it in GitHub Desktop.
version_info.rb
require 'version_info/data'
require 'version_info/tasks'
module VersionInfo
# current segments or defaults
def self.segments
@segments ||= [:major, :minor, :patch]
end
# define segments
def self.segments=(values)
@segments = values
end
def self.included(other)
other.const_set('VERSION', Data.new)
end
end
module VersionInfo
class Tasks
def self.install(klass, opts = {})
self.new(klass, opts).install
end
attr_reader :target
def initialize(klass, opts)
@target = opts.delete(:class)
self.extend(self.class.const_get(klass.to_s))
self.configure(opts)
end
module Rake
attr_reader :root_path
def configure(opts={})
self.extend Rake::DSL # have to check if this would work
# set up the root_path, etc.
end
def install
# same as you have it
end
end
module Thor
def configure(opts={})
# nothing needed here?
end
def install
Class.new(::Thor) do
desc 'show', "Show version tag and create version_info.yml if missing"
def show
puts target::VERSION.tag
target::VERSION.save unless File.exist?(target::VERSION.file_name)
end
#etc.
end
end
end
end
end
VersionInfo::Tasks.install :Thor, :class => MyProject
VersionInfo::Tasks.install :Rake, :class => MyProject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment