Module: Rake::DevEiate::Gemspec

Extended by:
Rake::DSL
Defined in:
lib/rake/deveiate/gemspec.rb

Overview

Gemspec-generation tasks

Constant Summary collapse

AUTHOR_PATTERN =

Pattern for splitting parsed authors list items into name and email

/^(?<name>.*)\s<(?<email>.*)>$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#signing_keyObject

The path to the file used to sign released gems



21
22
23
# File 'lib/rake/deveiate/gemspec.rb', line 21

def signing_key
  @signing_key
end

Instance Method Details

#define_tasksObject

Define gemspec tasks



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rake/deveiate/gemspec.rb', line 42

def define_tasks
	super if defined?( super )

	gemspec_file = "#{self.name}.gemspec"

	if self.has_manifest?
		file( self.manifest_file )
		file( gemspec_file => self.manifest_file )
	else
		file( gemspec_file )
	end

	task( gemspec_file ) do |task|
		self.prompt.say "Updating gemspec"

		spec = self.make_prerelease_gemspec

		File.open( task.name, 'w' ) do |fh|
			fh.write( spec.to_ruby )
		end
	end

	desc "(Re)Generate the gemspec file"
	task :gemspec => gemspec_file

	CLEAN.include( gemspec_file.to_s )

	task :precheckin => :gemspec

	task( :gemspec_debug, &method(:do_gemspec_debug) )
	task :debug => :gemspec_debug
end

#do_gemspec_debug(task, args) ⇒ Object

Task function – output debugging for gemspec tasks.



77
78
79
80
81
82
83
84
# File 'lib/rake/deveiate/gemspec.rb', line 77

def do_gemspec_debug( task, args )
	gemspec = self.gemspec
	gemspec_src = gemspec.to_yaml

	self.prompt.say( "Gemspec:", color: :bright_green )
	self.prompt.say( self.indent(gemspec_src, 4) )
	self.prompt.say( "\n" )
end

#gemspecObject

Return the project’s Gem::Specification, creating it if necessary.



88
89
90
# File 'lib/rake/deveiate/gemspec.rb', line 88

def gemspec
	return @gemspec ||= self.make_gemspec
end

#make_gemspecObject

Return a Gem::Specification created from the project’s metadata.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rake/deveiate/gemspec.rb', line 101

def make_gemspec
	spec = Gem::Specification.new

	spec.name         = self.name
	spec.description  = self.description
	spec.homepage     = self.homepage
	spec.summary      = self.summary || self.extract_summary
	spec.files        = self.project_files
	spec.signing_key  = self.resolve_signing_key.to_s
	spec.cert_chain   = self.cert_files.map( &File.method(:expand_path) ).to_a
	spec.version      = self.version
	spec.licenses     = self.licenses
	spec.date         = Date.today

	spec.['allowed_push_host'] = self.allowed_push_host if self.allowed_push_host

	self.authors.each do |author|
		if ( m = author.match(AUTHOR_PATTERN) )
			spec.authors ||= []
			spec.authors << m[:name]
			spec.email ||= []
			spec.email << m[:email] if m[:email]
		else
			self.prompt.warn "Couldn't extract author name + email from %p" % [ author ]
		end
	end

	self.dependencies.each do |dep|
		if dep.runtime?
			spec.add_runtime_dependency( dep )
		else
			spec.add_development_dependency( dep )
		end
	end

	return spec
end

#make_prerelease_gemspecObject

Return a Gem::Specification with its properties modified to be suitable for a pre-release gem.



142
143
144
145
146
147
148
149
150
# File 'lib/rake/deveiate/gemspec.rb', line 142

def make_prerelease_gemspec
	spec = self.make_gemspec

	spec.version     = self.prerelease_version
	spec.signing_key = nil
	spec.cert_chain  = []

	return spec
end

#prerelease_versionObject

Return a version string



154
155
156
# File 'lib/rake/deveiate/gemspec.rb', line 154

def prerelease_version
	return "#{self.version.bump}.0.pre.#{Time.now.strftime("%Y%m%d%H%M%S")}"
end

#resetObject

Reset any cached data when project attributes change.



35
36
37
38
# File 'lib/rake/deveiate/gemspec.rb', line 35

def reset
	super if defined?( super )
	@gemspec = nil
end

#resolve_signing_keyObject

Resolve the path of the signing key



160
161
162
163
164
# File 'lib/rake/deveiate/gemspec.rb', line 160

def resolve_signing_key
	path = Pathname( self.signing_key ).expand_path
	path = path.readlink if path.symlink?
	return path
end

#setup(_name, **options) ⇒ Object

Set some defaults when the task lib is set up.



25
26
27
28
29
30
31
# File 'lib/rake/deveiate/gemspec.rb', line 25

def setup( _name, **options )
	super if defined?( super )

	@signing_key = options[:signing_key] || Gem.default_key_path

	@gemspec = nil
end

#validate_gemspec(packaging = true, strict = false) ⇒ Object

Validate the gemspec, raising a Gem::InvalidSpecificationException if it’s not valid.



95
96
97
# File 'lib/rake/deveiate/gemspec.rb', line 95

def validate_gemspec( packaging=true, strict=false )
	return self.gemspec.validate( packaging, strict )
end