Class: ActivestorageOcr::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ActivestorageOcr::Generators::InstallGenerator
- Defined in:
- lib/generators/activestorage_ocr/install/install_generator.rb
Overview
Installs the OCR server binary and creates a binstub.
This generator creates a bin/activestorage-ocr-server script that automatically downloads the binary if needed and runs it.
Usage
rails generate activestorage_ocr:install
What it does
- Creates bin/activestorage-ocr-server (wrapper script)
- Downloads binary to bin/dist/activestorage-ocr-server
- Adds bin/dist/ to .gitignore
Instance Method Summary collapse
- #create_binstub ⇒ Object
- #download_binary ⇒ Object
- #show_instructions ⇒ Object
- #update_gitignore ⇒ Object
Instance Method Details
#create_binstub ⇒ Object
27 28 29 30 |
# File 'lib/generators/activestorage_ocr/install/install_generator.rb', line 27 def create_binstub template "bin/activestorage-ocr-server", "bin/activestorage-ocr-server" chmod "bin/activestorage-ocr-server", 0o755 end |
#download_binary ⇒ Object
42 43 44 45 46 47 |
# File 'lib/generators/activestorage_ocr/install/install_generator.rb', line 42 def download_binary say "Downloading OCR server binary...", :green require "activestorage/ocr/binary" dist_dir = Rails.root.join("bin", "dist") ActiveStorage::Ocr::Binary.install!(path: dist_dir.to_s) end |
#show_instructions ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/generators/activestorage_ocr/install/install_generator.rb', line 49 def show_instructions say "" say "OCR server installed successfully!", :green say "" say "Add to your Procfile:", :yellow say " ocr: bin/activestorage-ocr-server --host 127.0.0.1 --port 9292" say "" say "Configure the server URL in config/initializers/activestorage_ocr.rb:", :yellow say " ActiveStorage::Ocr.configure do |config|" say " config.server_url = ENV.fetch('ACTIVESTORAGE_OCR_SERVER_URL', 'http://127.0.0.1:9292')" say " end" say "" end |
#update_gitignore ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/activestorage_ocr/install/install_generator.rb', line 32 def update_gitignore gitignore_path = Rails.root.join(".gitignore") return unless File.exist?(gitignore_path) gitignore_content = File.read(gitignore_path) return if gitignore_content.include?("/bin/dist") append_to_file ".gitignore", "\n# OCR server binary\n/bin/dist/\n" end |