Class: BundleBoss::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle_boss/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, bundler_options = {}, settings = {}) ⇒ Project

Returns a new instance of Project.



7
8
9
10
11
12
13
# File 'lib/bundle_boss/project.rb', line 7

def initialize(path, bundler_options = {}, settings = {})
  @bundler_options = bundler_options
  @settings = settings
  @path = File.expand_path(path)
  @hash = @path.hash
  @sha1 = sha1
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/bundle_boss/project.rb', line 5

def path
  @path
end

Instance Method Details

#bundleObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/bundle_boss/project.rb', line 55

def bundle
  BundleBoss::Watchdog.info name, 'Hardcore Bundle Action'

  stdout = bundle_install
  if stdout =~ /bundle update/
    if @settings['update']
      BundleBoss::Watchdog.info name, 'Updating...'
      bundle_update
      stdout = bundle_install
    end
  end

  if stdout.empty?
    BundleBoss::Watchdog.success(name)
  else
    BundleBoss::Watchdog.error(name, "#{stdout.gsub(/\e\[\w{1,2}m/,'')}")
  end

  @sha1 = sha1
end

#bundle_installObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bundle_boss/project.rb', line 35

def bundle_install
  install_cmd = []
  install_cmd << "#{bundle_path} install"
  install_cmd << "--gemfile #{@path}/Gemfile"
  install_cmd << "--quiet"
  @bundler_options.each do |key,value|
    install_cmd << "--#{key}" if value
    install_cmd << value if value.is_a? String
  end
  run install_cmd
end

#bundle_pathObject



47
48
49
# File 'lib/bundle_boss/project.rb', line 47

def bundle_path
  "#{ENV['HOME']}/.rbenv/shims/bundle"
end

#bundle_updateObject



19
20
21
22
23
24
# File 'lib/bundle_boss/project.rb', line 19

def bundle_update
  update_cmd = []
  update_cmd << "cd #{@path};"
  update_cmd << "#{bundle_path} update"
  run update_cmd
end

#gemfile_changed?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/bundle_boss/project.rb', line 51

def gemfile_changed?
  @sha1 != sha1
end

#nameObject



76
77
78
# File 'lib/bundle_boss/project.rb', line 76

def name
  @path.split('/').last
end

#run(cmd) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/bundle_boss/project.rb', line 26

def run(cmd)
  stdout = nil
  ::Bundler.with_clean_env do
    ENV['RBENV_DIR'] = "#{@path}/"
    stdout = `#{cmd.join(' ')}`
  end
  stdout
end

#sha1Object



15
16
17
# File 'lib/bundle_boss/project.rb', line 15

def sha1
  Digest::SHA1.hexdigest File.read(@path + '/Gemfile')
end