Class: Assets::Environment::Cache

Inherits:
Assets::Environment show all
Includes:
Adamantium::Flat
Defined in:
lib/assets/environment/cache.rb

Overview

Environment that caches assets

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize object

Parameters:



35
36
37
# File 'lib/assets/environment/cache.rb', line 35

def initialize(environment)
  @environment, @cache = environment, {}
end

Instance Attribute Details

#environmentEnvironment (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return inner environment

Returns:



13
14
15
# File 'lib/assets/environment/cache.rb', line 13

def environment
  @environment
end

Class Method Details

.build(rules) ⇒ Cache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build cache environemnt

Parameters:

  • rules (Enumerable<Rules>)

Returns:



23
24
25
# File 'lib/assets/environment/cache.rb', line 23

def self.build(rules)
  new(Dynamic.new(rules))
end

Instance Method Details

#get(name) ⇒ Asset?

Return asset

Parameters:

  • name (String)

Returns:

  • (Asset)

    if found

  • (nil)

    otherwise



65
66
67
68
69
70
71
72
73
74
# File 'lib/assets/environment/cache.rb', line 65

def get(name)
  rule = rule(name) 
  return unless rule

  asset = @cache.fetch(name) do
    return miss(rule)
  end

  hit(rule, asset)
end

#rule(name) ⇒ Rule?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return rule

Parameters:

  • name (String)

Returns:

  • (Rule)

    if found

  • (nil)

    otherwise



51
52
53
# File 'lib/assets/environment/cache.rb', line 51

def rule(name)
  environment.rule(name)
end