Class: Markymark::PumadevManager
- Inherits:
-
Object
- Object
- Markymark::PumadevManager
- Defined in:
- lib/markymark/pumadev_manager.rb
Overview
Manages pumadev integration for markymark
Class Method Summary collapse
-
.active? ⇒ Boolean
Check if pumadev mode is currently active.
- .env_file_path ⇒ Object
-
.gem_directory ⇒ Object
Get the gem installation directory.
- .marker_file_path ⇒ Object
-
.puma_dev_installed? ⇒ Boolean
Check if puma-dev is installed.
-
.setup(path = nil) ⇒ Object
Setup pumadev integration.
-
.status ⇒ Object
Get current status.
-
.switch_directory(new_path) ⇒ Object
Switch directory in pumadev mode.
- .symlink_path ⇒ Object
-
.teardown ⇒ Object
Teardown pumadev integration.
Class Method Details
.active? ⇒ Boolean
Check if pumadev mode is currently active
22 23 24 |
# File 'lib/markymark/pumadev_manager.rb', line 22 def active? File.exist?(marker_file_path) && File.symlink?(symlink_path) end |
.env_file_path ⇒ Object
13 14 15 |
# File 'lib/markymark/pumadev_manager.rb', line 13 def env_file_path File.('~/.markymark/.pumadev_root') end |
.gem_directory ⇒ Object
Get the gem installation directory
32 33 34 35 36 37 38 |
# File 'lib/markymark/pumadev_manager.rb', line 32 def gem_directory gem_spec = Gem::Specification.find_by_name('markymark') gem_spec.gem_dir rescue Gem::LoadError # If gem not found, we're in development mode File.(File.join(__dir__, '..', '..')) end |
.marker_file_path ⇒ Object
17 18 19 |
# File 'lib/markymark/pumadev_manager.rb', line 17 def marker_file_path File.('~/.markymark/.pumadev_mode') end |
.puma_dev_installed? ⇒ Boolean
Check if puma-dev is installed
27 28 29 |
# File 'lib/markymark/pumadev_manager.rb', line 27 def puma_dev_installed? `which puma-dev`.strip != '' end |
.setup(path = nil) ⇒ Object
Setup pumadev integration
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/markymark/pumadev_manager.rb', line 41 def setup(path = nil) ensure_puma_dev_installed! gem_dir = gem_directory puma_dev_dir = File.dirname(symlink_path) # Create ~/.puma-dev if it doesn't exist FileUtils.mkdir_p(puma_dev_dir) unless File.exist?(puma_dev_dir) # Create symlink to gem directory if File.symlink?(symlink_path) existing_target = File.readlink(symlink_path) if existing_target == gem_dir puts "Pumadev symlink already exists and points to correct location" else puts "Updating pumadev symlink from #{existing_target} to #{gem_dir}" File.delete(symlink_path) File.symlink(gem_dir, symlink_path) end elsif File.exist?(symlink_path) raise "#{symlink_path} exists but is not a symlink. Please remove it manually." else puts "Creating pumadev symlink: #{symlink_path} -> #{gem_dir}" File.symlink(gem_dir, symlink_path) end # Store the root path if provided if path = File.(path) unless File.directory?() raise ArgumentError, "Path is not a directory: #{path}" end save_root_path() puts "Set markymark root directory to: #{}" else save_root_path(Dir.pwd) puts "Set markymark root directory to: #{Dir.pwd}" end # Create marker file FileUtils.mkdir_p(File.dirname(marker_file_path)) File.write(marker_file_path, Time.now.to_s) puts "\nPumadev setup complete!" puts "Access markymark at: http://markymark.test" puts "\nNote: It may take a few seconds for pumadev to start the app on first access." true rescue => e warn "Failed to setup pumadev: #{e.}" false end |
.status ⇒ Object
Get current status
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/markymark/pumadev_manager.rb', line 131 def status if active? root_path = load_root_path { mode: :pumadev, url: 'http://markymark.test', root_path: root_path, message: "Running via pumadev at http://markymark.test\nServing: #{root_path}" } else nil end end |
.switch_directory(new_path) ⇒ Object
Switch directory in pumadev mode
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/markymark/pumadev_manager.rb', line 146 def switch_directory(new_path) = File.(new_path) unless File.directory?() raise ArgumentError, "Path is not a directory: #{new_path}" end save_root_path() puts "Switched to #{}" puts "Restart required - touch your ~/.puma-dev/markymark symlink or wait for next request" # Trigger a restart by touching the restart.txt file restart_txt = File.join(gem_directory, 'tmp', 'restart.txt') FileUtils.mkdir_p(File.dirname(restart_txt)) FileUtils.touch(restart_txt) true rescue => e warn "Failed to switch directory: #{e.}" false end |
.symlink_path ⇒ Object
9 10 11 |
# File 'lib/markymark/pumadev_manager.rb', line 9 def symlink_path File.('~/.puma-dev/markymark') end |
.teardown ⇒ Object
Teardown pumadev integration
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/markymark/pumadev_manager.rb', line 95 def teardown removed_anything = false # Remove symlink if File.symlink?(symlink_path) File.delete(symlink_path) puts "Removed pumadev symlink" removed_anything = true end # Remove root path file if File.exist?(env_file_path) File.delete(env_file_path) removed_anything = true end # Remove marker file if File.exist?(marker_file_path) File.delete(marker_file_path) removed_anything = true end if removed_anything puts "Pumadev integration removed" puts "The app will stop automatically when pumadev next restarts" else puts "Pumadev integration was not active" end true rescue => e warn "Error during pumadev teardown: #{e.}" false end |