Module: OnContainer::Dev::BundlerOps

Defined in:
lib/on_container/dev/bundler_ops.rb

Instance Method Summary collapse

Instance Method Details

#bundle_belongs_to_current_user?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/on_container/dev/bundler_ops.rb', line 18

def bundle_belongs_to_current_user?
  bundle_owner_id == current_user_id
end

#bundle_owner_idObject



10
11
12
# File 'lib/on_container/dev/bundler_ops.rb', line 10

def bundle_owner_id
  File.stat(bundle_path).uid
end

#bundle_pathObject



6
7
8
# File 'lib/on_container/dev/bundler_ops.rb', line 6

def bundle_path
  '/usr/local/bundle'
end

#current_user_idObject



14
15
16
# File 'lib/on_container/dev/bundler_ops.rb', line 14

def current_user_id
  Etc.getpwuid.uid
end

#ensure_bundle_belongs_to_current_userObject



27
28
29
30
31
# File 'lib/on_container/dev/bundler_ops.rb', line 27

def ensure_bundle_belongs_to_current_user
  return if bundle_belongs_to_current_user?

  make_bundle_belong_to_current_user
end

#ensure_project_gems_are_installedObject



33
34
35
36
37
# File 'lib/on_container/dev/bundler_ops.rb', line 33

def ensure_project_gems_are_installed
  ensure_bundle_belongs_to_current_user

  system 'bundle check || bundle install'
end

#make_bundle_belong_to_current_userObject



22
23
24
25
# File 'lib/on_container/dev/bundler_ops.rb', line 22

def make_bundle_belong_to_current_user
  target_ownership = "#{current_user_id}:#{current_user_id}"
  system "sudo chown -R #{target_ownership} #{bundle_path}"
end