Class: Torba::ImportList

Inherits:
Object
  • Object
show all
Defined in:
lib/torba/import_list.rb

Overview

Represents a list of assets to be imported from a remote source.

Since:

  • 0.1.0

Defined Under Namespace

Classes: Asset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assets) ⇒ ImportList

Returns a new instance of ImportList.

Since:

  • 0.1.0



21
22
23
# File 'lib/torba/import_list.rb', line 21

def initialize(assets)
  @assets = assets
end

Instance Attribute Details

#assetsArray<Asset> (readonly)

Returns full list of assets to be imported.

Returns:

  • (Array<Asset>)

    full list of assets to be imported.

Since:

  • 0.1.0



19
20
21
# File 'lib/torba/import_list.rb', line 19

def assets
  @assets
end

Instance Method Details

#css_assetsArray<Asset>

Returns list of stylesheets to be imported.

Returns:

  • (Array<Asset>)

    list of stylesheets to be imported.

Since:

  • 0.1.0



33
34
35
# File 'lib/torba/import_list.rb', line 33

def css_assets
  assets.find_all { |asset| asset.css? }
end

#find_by_absolute_path(path) ⇒ Asset

Returns asset with given path.

Parameters:

  • path (String)

    absolute path of an asset.

Returns:

  • (Asset)

    asset with given path.

Raises:

Since:

  • 0.1.0



28
29
30
# File 'lib/torba/import_list.rb', line 28

def find_by_absolute_path(path)
  assets.find { |asset| asset.absolute_path == path } || raise(Errors::AssetNotFound.new(path))
end

#non_css_assetsArray<Asset>

Returns list of assets to be imported except stylesheets.

Returns:

  • (Array<Asset>)

    list of assets to be imported except stylesheets.

Since:

  • 0.1.0



38
39
40
# File 'lib/torba/import_list.rb', line 38

def non_css_assets
  assets.find_all { |asset| !asset.css? }
end

#non_js_css_assetsArray<Asset>

Returns list of assets to be imported except javascripts and stylesheets.

Returns:

  • (Array<Asset>)

    list of assets to be imported except javascripts and stylesheets.

Since:

  • 0.3.0



45
46
47
# File 'lib/torba/import_list.rb', line 45

def non_js_css_assets
  assets.find_all { |asset| !(asset.js? || asset.css?) }
end