Class: YamlManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/baidu_ueditor_rails/asset_manifest.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ YamlManifest

Returns a new instance of YamlManifest.



19
20
21
22
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 19

def initialize(file)
  @file = file
  @manifest = YAML.load_file(file)
end

Class Method Details

.try(manifest_path) ⇒ Object



14
15
16
17
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 14

def self.try(manifest_path)
  yaml_file = File.join(manifest_path, "manifest.yml")
  new(yaml_file) if File.exists?(yaml_file)
end

Instance Method Details

#append(logical_path, file) ⇒ Object



24
25
26
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 24

def append(logical_path, file)
  @manifest[logical_path] = logical_path
end

#dump(io = nil) ⇒ Object



49
50
51
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 49

def dump(io=nil)
  YAML.dump(@manifest, io)
end

#each(pattern) ⇒ Object



39
40
41
42
43
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 39

def each(pattern)
  @manifest.each_key do |asset|
    yield asset if asset =~ pattern
  end
end

#remove(logical_path) ⇒ Object



28
29
30
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 28

def remove(logical_path)
  @manifest.delete(logical_path)
end

#remove_digest(logical_path) ⇒ Object



32
33
34
35
36
37
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 32

def remove_digest(logical_path)
  if digested = @manifest[logical_path]
    @manifest[logical_path] = logical_path
    yield digested, logical_path if block_given?
  end
end

#to_sObject



45
46
47
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 45

def to_s
  dump
end

#writeObject



53
54
55
# File 'lib/baidu_ueditor_rails/asset_manifest.rb', line 53

def write
  File.open(@file, "wb") { |f| dump(f) }
end