mfm/src/models/concerns/base.cr
Glenn 23d4def217
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
feat: implement local & global mount_point definition
2023-11-24 00:20:16 +01:00

51 lines
1.2 KiB
Crystal

module GX::Models::Concerns
module Base
def mounted?() : Bool
mount_point_safe = @mount_point
raise "Invalid mountpoint value" if mount_point_safe.nil?
`mount`.includes?(" on #{mount_point_safe} type ")
end
def umount() : Nil
mount_point_safe = @mount_point
raise "Invalid mountpoint value" if mount_point_safe.nil?
system("fusermount -u #{mount_point_safe.shellescape}")
fusermount_status = $?
if fusermount_status.success?
puts "Models #{name} is now closed.".colorize(:green)
else
puts "Error: Unable to unmount filesystem #{name} (exit code: #{fusermount_status.exit_code}).".colorize(:red)
end
end
def mount_point?()
!mount_point.nil?
end
def mount()
_mount_wrapper() do
_mount_action
end
end
def _mount_wrapper(&block) : Nil
mount_point_safe = mount_point
return if mount_point_safe.nil?
Dir.mkdir_p(mount_point_safe) unless Dir.exists?(mount_point_safe)
if mounted?
puts "Already mounted. Skipping.".colorize(:yellow)
return
end
yield
puts "Models #{name} is now available on #{mount_point_safe}".colorize(:green)
end
end
end