Module: OnContainer::Dev::NodeModulesOps

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

Constant Summary collapse

APP_PATH =
File.expand_path '.'

Instance Method Summary collapse

Instance Method Details

#current_user_idObject



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

def current_user_id
  Etc.getpwuid.uid
end

#ensure_node_modules_belong_to_current_userObject



31
32
33
34
35
# File 'lib/on_container/dev/node_modules_ops.rb', line 31

def ensure_node_modules_belong_to_current_user
  return if node_modules_belong_to_current_user?

  make_node_modules_belong_to_current_user
end

#ensure_project_node_packages_are_installedObject



37
38
39
40
41
# File 'lib/on_container/dev/node_modules_ops.rb', line 37

def ensure_project_node_packages_are_installed
  ensure_node_modules_belong_to_current_user

  system 'yarn check --integrity || yarn install'
end

#make_node_modules_belong_to_current_userObject



26
27
28
29
# File 'lib/on_container/dev/node_modules_ops.rb', line 26

def make_node_modules_belong_to_current_user
  target_ownership = "#{current_user_id}:#{current_user_id}"
  system "sudo chown -R #{target_ownership} #{node_modules_path}"
end

#node_modules_belong_to_current_user?Boolean

Returns:

  • (Boolean)


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

def node_modules_belong_to_current_user?
  node_modules_owner_id == current_user_id
end

#node_modules_owner_idObject



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

def node_modules_owner_id
  File.stat(node_modules_path).uid
end

#node_modules_pathObject



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

def node_modules_path
  "#{APP_PATH}/node_modules"
end