Class: Observ::AssetInstaller
- Inherits:
-
Object
- Object
- Observ::AssetInstaller
- Defined in:
- lib/observ/asset_installer.rb
Overview
Main service class for installing Observ assets in a Rails application
Constant Summary collapse
- DEFAULT_STYLES_DEST =
"app/javascript/stylesheets/observ"- DEFAULT_JS_DEST =
"app/javascript/controllers/observ"
Instance Attribute Summary collapse
-
#app_root ⇒ Object
readonly
Returns the value of attribute app_root.
-
#gem_root ⇒ Object
readonly
Returns the value of attribute gem_root.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(gem_root:, app_root:, logger: $stdout) ⇒ AssetInstaller
constructor
A new instance of AssetInstaller.
-
#install(styles_dest: nil, js_dest: nil, generate_index: true) ⇒ Hash
Install assets with custom or default destinations.
-
#sync(styles_dest: nil, js_dest: nil) ⇒ Hash
Sync existing assets (update only).
Constructor Details
#initialize(gem_root:, app_root:, logger: $stdout) ⇒ AssetInstaller
Returns a new instance of AssetInstaller.
14 15 16 17 18 |
# File 'lib/observ/asset_installer.rb', line 14 def initialize(gem_root:, app_root:, logger: $stdout) @gem_root = Pathname.new(gem_root) @app_root = Pathname.new(app_root) @logger = logger end |
Instance Attribute Details
#app_root ⇒ Object (readonly)
Returns the value of attribute app_root.
6 7 8 |
# File 'lib/observ/asset_installer.rb', line 6 def app_root @app_root end |
#gem_root ⇒ Object (readonly)
Returns the value of attribute gem_root.
6 7 8 |
# File 'lib/observ/asset_installer.rb', line 6 def gem_root @gem_root end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/observ/asset_installer.rb', line 6 def logger @logger end |
Instance Method Details
#install(styles_dest: nil, js_dest: nil, generate_index: true) ⇒ Hash
Install assets with custom or default destinations
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 |
# File 'lib/observ/asset_installer.rb', line 25 def install(styles_dest: nil, js_dest: nil, generate_index: true) styles_dest ||= DEFAULT_STYLES_DEST js_dest ||= DEFAULT_JS_DEST styles_dest_path = app_root.join(styles_dest) js_dest_path = app_root.join(js_dest) log_header(styles_dest_path, js_dest_path) syncer = AssetSyncer.new(gem_root: gem_root, app_root: app_root, logger: logger) # Sync stylesheets styles_result = syncer.sync_stylesheets(styles_dest_path) log "" # Sync JavaScript controllers js_result = syncer.sync_javascript_controllers(js_dest_path) log "" # Check controller registration if requested # Note: index.js is already included in the gem's source files and gets synced, # so we don't need to generate it - we just check if it's properly registered registration_status = nil if generate_index generator = IndexFileGenerator.new(app_root: app_root, logger: logger) log "Checking controller registration..." log "-" * 80 registration_status = generator.check_main_controllers_registration if registration_status[:suggestions] registration_status[:suggestions].each { |msg| log " #{msg}" } elsif registration_status[:registered] log " ✓ Observ controllers are already registered" end log "" end (styles_dest_path, js_dest_path) { styles: styles_result, javascript: js_result, registration: registration_status, paths: { styles: styles_dest_path, javascript: js_dest_path } } end |
#sync(styles_dest: nil, js_dest: nil) ⇒ Hash
Sync existing assets (update only)
81 82 83 |
# File 'lib/observ/asset_installer.rb', line 81 def sync(styles_dest: nil, js_dest: nil) install(styles_dest: styles_dest, js_dest: js_dest, generate_index: false) end |