Module: Gemspec

Extended by:
CamelizeMethod, Memoist
Defined in:
lib/gemspec.rb,
lib/gemspec/git.rb,
lib/gemspec/version.rb,
lib/gemspec/camelize.rb,
lib/gemspec/base_dirname.rb,
lib/gemspec/bootstrap_lib.rb

Defined Under Namespace

Modules: CamelizeMethod, Git

Constant Summary collapse

VERSION =
File.read(File.expand_path("../VERSION", __FILE__))
VERSION_FOR_HUMANS =
File.read(File.expand_path("../VERSION_FOR_HUMANS", __FILE__))

Class Method Summary collapse

Class Method Details

.base_dirname(file) ⇒ Object



6
7
8
# File 'lib/gemspec/base_dirname.rb', line 6

def base_dirname(file)
  Pathname.new(file).dirname.realdirpath.basename.to_s
end

.boilerplate(s) ⇒ Object

These settings shouldn’t change as long as you follow conventions



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gemspec.rb', line 16

def boilerplate(s)
  Dir.exist?('.git') || system('git', 'init', '.')

  #Naming according to conventions
  s.["namespaced_path"] = s.name.tr('-', '/')
  s.["constant_name"] = camelize(s.["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.["namespaced_path"]}/version"
  spec_module         = Object.const_get(s.["constant_name"])
  s.version        = spec_module::VERSION
  s.["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) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gemspec/bootstrap_lib.rb', line 17

def bootstrap_lib!(spec)

  config = {}
  config["constant_name"] = spec.["constant_name"] || camelize(["namespaced_path"])
  config["namespaced_path"] = spec.["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') unless File.exist?(versionfile)
  File.write(human_versionfile, '0.1.0') unless File.exist?(human_versionfile)
end

.template_write(filename, config, template_str) ⇒ Object



47
48
49
# File 'lib/gemspec/bootstrap_lib.rb', line 47

def template_write(filename, config, template_str)
  File.write(filename, ERB.new(template_str, nil,'-').result(binding))
end