module Gemspec
Constants
- VERSION
- VERSION_FOR_HUMANS
Public Instance Methods
base_dirname(file)
click to toggle source
# File lib/gemspec/base_dirname.rb, line 5 def base_dirname(file) Pathname.new(file).dirname.realdirpath.basename.to_s end
boilerplate(s)
click to toggle source
These settings shouldn't change as long as you follow conventions
# File lib/gemspec.rb, line 15 def boilerplate(s) #Naming according to conventions s.metadata["namespaced_path"] = s.name.tr('-', '/') s.metadata["constant_name"] = camelize(s.metadata["namespaced_path"]) #Add lib to path so that the version file can be loaded lib = File.expand_path('lib') $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) #Bootstrap the lib directory along with the basic *.rb files #This won't overwrite existing files Gemspec::bootstrap_lib!(s) #Get VERSION and VERSION_FOR_HUMANS from the version file require "#{s.metadata["namespaced_path"]}/version" spec_module = Object.const_get(s.metadata["constant_name"]) s.version = spec_module::VERSION s.metadata["human_version"] = spec_module::VERSION_FOR_HUMANS #Specify common paths and files s.test_files = Git::ls_files.grep(%r{^(test|s|features)/}) s.files = Git::ls_files.reject { |f| f.match(%r{^(test|s|features)/}) } s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } s.require_paths = ["lib"] #Authors are all committers or `git config user.name` if the former is empty s.authors = Git::ls_authors end
bootstrap_lib!(spec)
click to toggle source
# File lib/gemspec/bootstrap_lib.rb, line 17 def bootstrap_lib!(spec) system('git', 'status', out: '/dev/null') || system(*%w[git init .]) config = {} config["constant_name"] = spec.metadata["constant_name"] || camelize(metadata["namespaced_path"]) config["namespaced_path"] = spec.metadata["namespaced_path"] || spec.name.tr('-', '/') config["constant_array"] = config["constant_name"].split("::") path = "lib/#{config["namespaced_path"]}" versionfilerb = "#{path}/version.rb" versionfile = "#{path}/VERSION" human_versionfile = "#{path}/VERSION_FOR_HUMANS" rbfile = "#{path}.rb" FileUtils.mkdir_p path template_write(rbfile, config, templates["newgem.tt"]) unless File.exist?(rbfile) template_write(versionfilerb, config, templates["version.rb.tt"]) unless File.exist?(versionfilerb) File.write(versionfile, '0.1.0' + "\n") unless File.exist?(versionfile) File.symlink(versionfile, "VERSION") unless File.exist?("VERSION") File.write(human_versionfile, '0.1' + "\n") unless File.exist?(human_versionfile) File.symlink(human_versionfile, "VERSION_FOR_HUMANS") unless File.exist?("VERSION_FOR_HUMANS") end
current()
click to toggle source
# File lib/gemspec.rb, line 45 def current spec = nil Git.cdroot do spec = Gem::Specification.load('gemspec.gemspec') end spec end
template_write(filename, config, template_str)
click to toggle source
# File lib/gemspec/bootstrap_lib.rb, line 50 def template_write(filename, config, template_str) File.write(filename, ERB.new(template_str, nil,'-').result(binding)) end
templates()
click to toggle source
# File lib/gemspec/bootstrap_lib.rb, line 41 def templates ret = nil File.open(__FILE__) do |this_file| this_file.find { |line| line =~ /^__END__ *$/ } ret = YAML.load(this_file.read) end return ret end