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
|
# File 'lib/gemspec.rb', line 16
def boilerplate(s)
s.metadata["namespaced_path"] = s.name.tr('-', '/')
s.metadata["constant_name"] = camelize(s.metadata["namespaced_path"])
lib = File.expand_path('lib')
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gemspec::bootstrap_lib!(s)
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
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"]
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
37
38
39
|
# 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
|
.template_write(filename, config, template_str) ⇒ Object
50
51
52
|
# 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
|