Class: Observ::AssetSyncer

Inherits:
Object
  • Object
show all
Defined in:
lib/observ/asset_syncer.rb

Overview

Service class for syncing assets from the gem to the host application

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_root:, app_root:, logger: $stdout) ⇒ AssetSyncer

Returns a new instance of AssetSyncer.

Parameters:

  • gem_root (String, Pathname)

    Root directory of the gem

  • app_root (String, Pathname)

    Root directory of the host application

  • logger (Logger, IO) (defaults to: $stdout)

    Logger for output (defaults to STDOUT)



11
12
13
14
15
# File 'lib/observ/asset_syncer.rb', line 11

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_rootObject (readonly)

Returns the value of attribute app_root.



6
7
8
# File 'lib/observ/asset_syncer.rb', line 6

def app_root
  @app_root
end

#gem_rootObject (readonly)

Returns the value of attribute gem_root.



6
7
8
# File 'lib/observ/asset_syncer.rb', line 6

def gem_root
  @gem_root
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/observ/asset_syncer.rb', line 6

def logger
  @logger
end

Instance Method Details

#sync_javascript_controllers(dest_path) ⇒ Hash

Sync JavaScript controllers to the destination path

Parameters:

  • dest_path (String, Pathname)

    Destination directory

Returns:

  • (Hash)

    Statistics about the sync operation



33
34
35
36
37
38
39
40
41
# File 'lib/observ/asset_syncer.rb', line 33

def sync_javascript_controllers(dest_path)
  source_path = gem_root.join("app", "assets", "javascripts", "observ", "controllers")
  sync_files(
    source_path: source_path,
    dest_path: Pathname.new(dest_path),
    pattern: "*.js",
    label: "JavaScript controllers"
  )
end

#sync_stylesheets(dest_path) ⇒ Hash

Sync stylesheets to the destination path

Parameters:

  • dest_path (String, Pathname)

    Destination directory

Returns:

  • (Hash)

    Statistics about the sync operation



20
21
22
23
24
25
26
27
28
# File 'lib/observ/asset_syncer.rb', line 20

def sync_stylesheets(dest_path)
  source_path = gem_root.join("app", "assets", "stylesheets", "observ")
  sync_files(
    source_path: source_path,
    dest_path: Pathname.new(dest_path),
    pattern: "*.scss",
    label: "stylesheets"
  )
end