Created
September 14, 2011 02:23
-
-
Save ericgj/1215719 to your computer and use it in GitHub Desktop.
version_info.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VersionInfo::Tasks.install :Thor, :class => MyProject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VersionInfo::Tasks.install :Rake, :class => MyProject |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment