class Extensionator::Manifest

Public Class Methods

new(dir) click to toggle source
# File lib/extensionator/manifest.rb, line 7
def initialize(dir)
  manifest_file = "#{dir}/manifest.json"

  raise "Can't find manifest file" unless File.exists? manifest_file

  begin
    @manifest = JSON.parse(File.read(manifest_file))
  rescue Errno::ENOTENT => e
    raise ValidationError.new("Can't read manifest file: #{e.message}")
  rescue JSON::ParserError => e
    raise ValidationError.new("Can't parse manifest file: #{e.message}")
  end
end

Public Instance Methods

inject_key(priv_key) click to toggle source
# File lib/extensionator/manifest.rb, line 26
def inject_key(priv_key)
  #Chrome appears to support some shorter encoding of the pub key, but I'm not sure what it is
  @manifest["key"] = Base64.encode64(priv_key.public_key.to_der).gsub("\n", "")
  @updated = true
end
inject_version(version) click to toggle source
# File lib/extensionator/manifest.rb, line 37
def inject_version(version)
  @manifest["version"] = version
  @updated = true
end
strip_key() click to toggle source
# File lib/extensionator/manifest.rb, line 32
def strip_key
  @manifest.delete("key")
  @updated = true
end
updated?() click to toggle source
# File lib/extensionator/manifest.rb, line 42
def updated?
  @updated || false
end
validate(paths) click to toggle source
# File lib/extensionator/manifest.rb, line 21
def validate(paths)
  #todo: actual validations!
  true
end
write() click to toggle source
# File lib/extensionator/manifest.rb, line 46
def write
  dir = "/tmp/extensionator"
  FileUtils.mkdir_p(dir)
  file = "#{dir}/crx-manifest.json"
  content = JSON.pretty_generate(@manifest)
  File.open(file, "w"){|f| f.write(content)}
  ["manifest.json", file]
end