Created
May 16, 2017 17:50
-
-
Save samsm/f407d5102ed0313cf03f369b07dadbdd to your computer and use it in GitHub Desktop.
A workaround for the gemname/version.rb practice that isn't broken exactly but I don't care for it.
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
# coding: utf-8 | |
lib = File.expand_path('../lib', __FILE__) | |
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
# require "something/version" <- hells no | |
Gem::Specification.new do |spec| | |
spec.name = "something" | |
spec.version = "1.2.3" # <- makes sense here, right? | |
# ... gemspec guts ... | |
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 Something | |
# But what if I want Something::VERSION in the code? | |
# No problem: | |
def self.const_missing(constant) | |
if constant == :VERSION | |
require "rubygems" | |
spec_location = File.expand_path("../../something.gemspec", __FILE__) | |
spec = Gem::Specification::load(spec_location) | |
const_set(:VERSION, spec.version.to_s) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment