Class: TinyMCE::JsonManifest

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ JsonManifest

Returns a new instance of JsonManifest.



65
66
67
68
# File 'lib/tinymce/rails/asset_manifest.rb', line 65

def initialize(file)
  @file = file
  @manifest = MultiJson.load(File.read(file))
end

Class Method Details

.try(manifest_path) ⇒ Object



60
61
62
63
# File 'lib/tinymce/rails/asset_manifest.rb', line 60

def self.try(manifest_path)
  paths = Dir[File.join(manifest_path, "manifest*.json")]
  new(paths.first) if paths.any?
end

Instance Method Details

#append(logical_path, file) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/tinymce/rails/asset_manifest.rb', line 70

def append(logical_path, file)
  stat = File.stat(file)
  
  @manifest["assets"][logical_path] = logical_path
  @manifest["files"][logical_path] = {
    "logical_path" => logical_path,
    "mtime"        => stat.mtime.iso8601,
    "size"         => stat.size,
    "digest"       => nil
  }
end

#dumpObject



106
107
108
# File 'lib/tinymce/rails/asset_manifest.rb', line 106

def dump
  MultiJson.dump(@manifest)
end

#each(pattern) ⇒ Object



96
97
98
99
100
# File 'lib/tinymce/rails/asset_manifest.rb', line 96

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

#remove(logical_path) ⇒ Object



82
83
84
85
86
# File 'lib/tinymce/rails/asset_manifest.rb', line 82

def remove(logical_path)
  if digested = @manifest["assets"].delete(logical_path)
    @manifest["files"].delete(digested)
  end
end

#remove_digest(logical_path) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/tinymce/rails/asset_manifest.rb', line 88

def remove_digest(logical_path)
  if digested = @manifest["assets"][logical_path]
    @manifest["assets"][logical_path] = logical_path
    @manifest["files"][logical_path] = @manifest["files"].delete(digested).tap { |f| f["digest"] = nil }
    yield digested, logical_path if block_given?
  end
end

#to_sObject



102
103
104
# File 'lib/tinymce/rails/asset_manifest.rb', line 102

def to_s
  dump
end

#writeObject



110
111
112
# File 'lib/tinymce/rails/asset_manifest.rb', line 110

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