Class: MidwireCommon::RakeHelper

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/midwire_common/rake_helper.rb

Overview

RakeHelper helps to automate gem release and versioning tasks rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ RakeHelper

Returns a new instance of RakeHelper.



17
18
19
# File 'lib/midwire_common/rake_helper.rb', line 17

def initialize(base)
  @base = base
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



15
16
17
# File 'lib/midwire_common/rake_helper.rb', line 15

def base
  @base
end

Class Method Details

.install_tasks(opts = {}) ⇒ Object



10
11
12
13
# File 'lib/midwire_common/rake_helper.rb', line 10

def self.install_tasks(opts = {})
  dir = opts[:dir] || Dir.pwd
  new(dir).install
end

Instance Method Details

#installObject



21
22
23
24
# File 'lib/midwire_common/rake_helper.rb', line 21

def install
  task_dir = File.expand_path('../tasks', File.dirname(__FILE__))
  Dir["#{task_dir}/*.rake"].sort.each { |ext| load ext }
end

#install_gemObject

def build_gem

file_name = nil
sh("gem build -V '#{spec_path}'") { |out, code|
  file_name = File.basename(built_gem_path)
  FileUtils.mkdir_p(File.join(base, 'pkg'))
  FileUtils.mv(built_gem_path, 'pkg')
  Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}"
}
File.join(base, 'pkg', file_name)

end



37
38
39
40
41
42
43
44
45
46
# File 'lib/midwire_common/rake_helper.rb', line 37

def install_gem
  built_gem_path = build_gem
  out, _ = sh_with_code("gem install '#{built_gem_path}'")
  msg = "    |Couldn't install gem, run `gem install \#{built_gem_path}'\n    | for more detailed output\n  string\n  fail msg unless out[/Successfully installed/]\n  Bundler.ui.confirm \"\#{name} (\#{version}) installed\"\nend\n".here_with_pipe

#release_gemObject



48
49
50
51
52
53
54
55
56
# File 'lib/midwire_common/rake_helper.rb', line 48

def release_gem
  guard_clean
  guard_already_tagged
  built_gem_path = build_gem
  tag_version do
    git_push
    rubygem_push(built_gem_path)
  end
end