Class: Henry::Bootstrap

Inherits:
Object
  • Object
show all
Defined in:
lib/henry/bootstrap.rb

Instance Method Summary collapse

Constructor Details

#initialize(shell = Thor.new) ⇒ Bootstrap

Returns a new instance of Bootstrap.



4
5
6
# File 'lib/henry/bootstrap.rb', line 4

def initialize(shell = Thor.new)
  @shell = shell
end

Instance Method Details

#add_henryObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/henry/bootstrap.rb', line 35

def add_henry
  @shell.say('Adding Henry to your .travis.yml', :green)
  t = travis
  t['after_success'] ||= []
  t['after_success'] << 'gem install henry'
  t['after_success'] << 'henry deploy'
  File.open('.travis.yml', 'w+') do |f|
    f.write(t.to_yaml)
  end
end

#create_projectObject



15
16
17
18
19
20
# File 'lib/henry/bootstrap.rb', line 15

def create_project
  return if File.exist?('.travis.yml')
  @shell.say("Your project doesn't seem to have a `.travis.yml` - creating one now", :green)
  version = @shell.ask('What version of Ruby do you want to test against? |2.1.4|')
  system "travis init ruby --rvm #{version.empty? ? '2.1.4' : version}"
end

#encrypt_api_keyObject



29
30
31
32
33
# File 'lib/henry/bootstrap.rb', line 29

def encrypt_api_key
  github_api_key = @shell.ask("Please enter your Github oauth token - visit https://github.com/settings/tokens/new?description=Henry%20Token to set one up if you haven't already")
  @shell.say('Encrypting your token and adding it to your .travis.yml', :green)
  `travis encrypt GITHUB_OUATH_TOKEN=#{github_api_key} --add`
end

#performObject



8
9
10
11
12
13
# File 'lib/henry/bootstrap.rb', line 8

def perform
  create_project
  setup_deployment
  encrypt_api_key
  add_henry
end

#setup_deploymentObject



22
23
24
25
26
27
# File 'lib/henry/bootstrap.rb', line 22

def setup_deployment
  if travis['deploy'].nil?
    @shell.say('Setting up deployment with Rubygems', :green)
    system "travis setup rubygems"
  end
end

#travisObject



46
47
48
# File 'lib/henry/bootstrap.rb', line 46

def travis
  YAML.load_file('.travis.yml')
end