Module: RunGemDev

Defined in:
lib/run-gem-dev/version.rb,
lib/run-gem-dev/gem_tasks.rb,
lib/run-gem-dev/rdoc_tasks.rb,
lib/run-gem-dev/rspec_tasks.rb,
lib/run-gem-dev/minitest_tasks.rb

Constant Summary collapse

VERSION =
"0.3.0"
@@default_rdoc_options =
[
	"--main README.md",
	"--all",
]

Class Method Summary collapse

Class Method Details

.gem_tasks(gemname, gemdir = "gems") ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
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
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/run-gem-dev/gem_tasks.rb', line 5

def self.gem_tasks(gemname, gemdir="gems")
	command "gem"

	spec = Gem::Specification::load "#{gemname}.gemspec"
	spec or abort "Error loading #{gemname}.gemspec"
	gemver = spec.version.to_s

	usage  "build [--install]"
	help   "Build gem from gemspec and move it to '#{gemdir}' folder.\nUse --install to also install it."
	action :build do |args|
		say "!txtgrn!Building gem"
		cmd = "gem build #{gemname}.gemspec"	
		say "!txtgrn!Running: !txtpur!#{cmd}"
		system cmd
		say "!txtgrn!Moving gem file to #{gemdir}"
		files = Dir["*.gem"]
		Dir.exist? gemdir or FileUtils.mkdir gemdir
		files.each {|f| FileUtils.mv f, gemdir }
		args['--install'] and call "gem install"
	end

	usage  "install [--remote]"
	help   "Install gem from local gem file or from rubygems (--remote)."
	action :install do |args|
		if args['--remote']
			cmd = "gem install #{gemname}"
		else
			gemfile = "gems/#{gemname}-#{gemver}.gem"
			cmd = "gem install #{gemfile}"
		end
		say "!txtgrn!Running: !txtpur!#{cmd}"
		system cmd
	end

	help   "Publish gem to rubygems. Make sure to 'run gem build' before you publish."
	action :publish do
		gemfile = "gems/#{gemname}-#{gemver}.gem"
		File.exist? gemfile or abort "File not found #{gemfile}"
		cmd = "gem push #{gemfile}"
		say "!txtgrn!Running: !txtpur!#{cmd}"
		system cmd
	end

	usage  "yank [<version>]"
	help   "Yank gem from rubygems."
	action :yank do |args|
		ver = args['<version>'] || gemver
		cmd = "gem yank #{gemname} -v #{ver}"
		say "!txtgrn!Running: !txtpur!#{cmd}"
		system cmd
	end
	
	endcommand
end

.minitest_tasks(pattern = "./test/*_test.rb") ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/run-gem-dev/minitest_tasks.rb', line 3

def self.minitest_tasks(pattern="./test/*_test.rb")
	usage  "test [<name>]"
	help   "Run all tests or a single test file."
	action :test do |args|
		if args['<name>'] 
			file = pattern.sub "*", args['<name>']
			say "!txtgrn!Using: !txtpur!#{file}"
			require file
		else
			Dir[pattern].each do |file| 
				say "!txtgrn!Using: !txtpur!#{file}"
				require file
			end
		end
	end
end

.rdoc_tasks(files = nil, options = @@default_rdoc_options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/run-gem-dev/rdoc_tasks.rb', line 8

def self.rdoc_tasks(files=nil, options=@@default_rdoc_options)
	files or files = Dir['**/*.{rb,md}']
	files = "'" + files.join("' '") + "'"
	usage  "rdoc [-- <options>...]"
	help   "Generate documentation using the rdoc command line tool. To pass arguments to rdoc, place them after '--'."
	action :rdoc do |args|
		inopts = args['<options>']
		options = inopts unless inopts.empty?
		options = options.join(' ')
		cmd = "rdoc #{options} #{files}"
		say "!txtgrn!Running: !txtpur!#{cmd}"
		system cmd
	end
end

.rspec_tasks(opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/run-gem-dev/rspec_tasks.rb', line 3

def self.rspec_tasks(opts={})
  opts = { action: opts } if opts.is_a? String
  
  opts = {
    action:  'spec', 
    pattern: './spec/**/*_spec.rb',
    command: 'rspec'
  }.merge opts

  usage  "#{opts[:action]} [<name>]"
  help   "Run all specs or a single spec file matching a regex."
  action opts[:action].to_sym do |args|
    if args['<name>'] 
      files = Dir[opts[:pattern]]  
      files.select! { |file| file =~ /#{args['<name>']}/i }
      abort "Cannot find a matching spec file with #{opts[:pattern]}" if files.empty?
      file = files.first
      cmd = "#{opts[:command]} \"#{file}\""
    else
      cmd = "#{opts[:command]}"
    end
    say "!txtgrn!Running: !txtpur!#{cmd}"
    system cmd
  end
end