Class: CabezaDeTermo::Assets::BundlesLibrary

Inherits:
Object
  • Object
show all
Defined in:
lib/cabeza-de-termo/assets/bundles/bundles-library.rb

Overview

A collection of named bundles.

Instance Method Summary collapse

Constructor Details

#initializeBundlesLibrary

Initialize the instance



10
11
12
# File 'lib/cabeza-de-termo/assets/bundles/bundles-library.rb', line 10

def initialize
	@bundles = Hash.new
end

Instance Method Details

#bundle(name, &block) ⇒ Object

Define a bundle named name and allow to :include assets and :require another bundles on it.



26
27
28
29
# File 'lib/cabeza-de-termo/assets/bundles/bundles-library.rb', line 26

def bundle(name, &block)
	@bundles[name] = new_bundle
	CdT.bind_block_evaluation_to @bundles[name], &block
end

#bundle_named(name) ⇒ Object

Answer the bundle named name or raise an error if not found.



20
21
22
23
# File 'lib/cabeza-de-termo/assets/bundles/bundles-library.rb', line 20

def bundle_named(name)
	raise_bundle_not_found_error(name) unless has_asset_named?(name)
	@bundles[name]
end

#has_asset_named?(name) ⇒ Boolean

Answer whether the library has the bundle named name or not.

Returns:

  • (Boolean)


15
16
17
# File 'lib/cabeza-de-termo/assets/bundles/bundles-library.rb', line 15

def has_asset_named?(name)
	@bundles.key? name
end

#new_bundleObject

Answer a new bundle



32
33
34
# File 'lib/cabeza-de-termo/assets/bundles/bundles-library.rb', line 32

def new_bundle
	Bundle.new
end

#raise_bundle_not_found_error(name) ⇒ Object



36
37
38
# File 'lib/cabeza-de-termo/assets/bundles/bundles-library.rb', line 36

def raise_bundle_not_found_error(name)
	raise BundleNotFoundError.new("Asset bundle '#{name}' not found.")
end