Class: Bunto::Assets::Liquid::Tag::ProxiedAsset

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bunto/assets/liquid/tag/proxied_asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset, args, env, tag) ⇒ ProxiedAsset




26
27
28
29
30
31
32
33
34
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 26

def initialize(asset, args, env, tag)
  @env = env
  @asset = asset
  @args = args
  @tag = tag

  cache_file
  proxy_file
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



14
15
16
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 14

def args
  @args
end

#assetObject (readonly)

Returns the value of attribute asset.



14
15
16
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 14

def asset
  @asset
end

#envObject (readonly)

Returns the value of attribute env.



14
15
16
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 14

def env
  @env
end

Instance Method Details

#cached?Boolean


Returns:

  • (Boolean)


38
39
40
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 38

def cached?
  @_cached
end

#digestObject




65
66
67
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 65

def digest
  Digest::SHA2.hexdigest(args.proxies.to_s)
end

#digest_pathObject




81
82
83
84
85
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 81

def digest_path
  name = asset.logical_path
  ext  = File.extname(name)
  "#{name.chomp(ext)}-#{digest}#{ext}"
end

#filenameObject




59
60
61
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 59

def filename
  env.in_cache_dir(digest_path)
end

#logical_pathObject


We always digest a proxied asset so it’s uniq based on what proxies you give us, it would be ignorant to treat it otherwise, we also make sure they are URL safe by digesting the args.




75
76
77
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 75

def logical_path
  digest_path
end

#sourceObject




53
54
55
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 53

def source
  File.binread(filename)
end

#write_to(name) ⇒ Object




44
45
46
47
48
49
# File 'lib/bunto/assets/liquid/tag/proxied_asset.rb', line 44

def write_to(name)
  FileUtils.mkdir_p File.dirname(name)
  Sprockets::PathUtils.atomic_write(name) do |f|
    f.write source
  end
end