# encoding: UTF-8 # frozen_string_literal: true ############################################################################## # This file is kind-of special: you should be able to load it totally # independently. # # This means you can go # # load 'path/to/gem/lib/locd/version.rb' # # and it will succeed, regardless of paths or gems or any other environment or # state. # # It defines a few very basic pieces of information about the app, and it turns # out to be incredibly useful on an adminstration level to be able to fire up # any old Ruby interpreter and pull that info in without worrying about all # the other shit you need to actually run it. # # In general, that means that this file shouldn't require anything, and # anything it does require must not depend on anything outside Ruby's standard # library. # # This file is loaded by `//locd.gemspec` to get the version information, # which is in turn loaded from the `//VERSION` file (see {Locd::VERSION}). # ############################################################################## # Requirements # ======================================================================== # Stdlib # ------------------------------------------------------------------------ require 'pathname' require 'singleton' # Definitions # ======================================================================== module Locd # Absolute, expanded path to the gem's root directory. # # @return [Pathname] # ROOT = Pathname.new( __dir__ ).join( '..', '..' ).expand_path # String version read from `//VERSION` and used in the gemspec. # # I use this approach in order to create a standard versioning system across # *any* package, regardless or runtime, and so that tools can figure out # what version a package is without even having it's runtime available. # # This has turned out to be super helpful, and I'm surprised it isn't more # common or standardized in some way... I think pretty much every package # in very language has a root directory and is capable of reading a file # to figure out it's state. # # @return [String] # VERSION = (ROOT + 'VERSION').read.chomp # The gem name, read from the `//NAME` file, and used in the gemspec. # # See {Locd::VERSION} for an explanation of why bare files in the package # root are used. # # @return [String] # GEM_NAME = (ROOT + 'NAME').read.chomp # {Singleton} extension of {Gem::Version} that loads {Locd::VERSION} and # provides some convenient methods. # class Version < Gem::Version include ::Singleton # Private method to instantiate the {#instance} using the {Locd::VERSION} # {String}. # # @return [Version] # def self.new super Locd::VERSION end # We need to mark {.new} as private to dissuade construction of additional # instances. private_class_method :new # Proxies to the {#instance}'s {#dev?}. # # @return (see #dev?) # def self.dev? instance.dev? end # Tests if the package's version is a development pre-release. # # @return [Boolean] # `true` if this is a development pre-release. # def dev? segments[3] == 'dev' end end # module Version end # module Locd