class Manifest

Attributes

filename[RW]
libraryname[RW]
schema_version[R]

Public Class Methods

descendants() click to toggle source
# File lib/manifest.rb, line 3
def self.descendants
  ObjectSpace.each_object(::Class).select { |klass| klass < self }
end
for_schema_id(schema_id) click to toggle source
# File lib/manifest.rb, line 7
def self.for_schema_id schema_id
  descendants.each do |manifest_class|
    if schema_id == manifest_class.schema_id
      return manifest_class.new
    end
  end
  raise VerificationError.new("Unknown schema id '#{schema_id}'")
end
new(schema_id) click to toggle source
Calls superclass method JsonObject::new
# File lib/manifest.rb, line 73
def initialize(schema_id)
  @schema_id = schema_id
  @schema_version = Manifest.parse_schema_version(schema_id)
  super()
end
parse_file(path) click to toggle source
# File lib/manifest.rb, line 16
def self.parse_file path
  json = JSON File.read path
  manifest = Manifest.for_schema_id(json["$schema"])
  manifest.filename = File.basename path
  manifest.filename =~ /^(.*?)\./
  manifest.libraryname = $1

  manifest.from_hash(json)
end
parse_schema_version(schema_id) click to toggle source
# File lib/manifest.rb, line 26
def self.parse_schema_version schema_id
  schema_id =~ /^http:\/\/inqlude\.org\/schema\/(.*)-manifest-v(.*)\#$/
  type = $1
  version = $2.to_i
  if !type || !version
    raise InqludeError.new("Unable to parse schema id '{schema_id}'")
  end
  version
end

Public Instance Methods

path() click to toggle source
# File lib/manifest.rb, line 92
def path
  File.join( name, expected_filename )
end
schema_name() click to toggle source
# File lib/manifest.rb, line 79
def schema_name
  regexp = /Manifest([A-Z][a-z]*)([A-Z][a-z]*)?/
  match = regexp.match(self.class.to_s)
  if !match
    raise "Class '#{self.class} is not a Manifest sub class"
  end
  schema_type = match[1].downcase
  if match[2]
    schema_type += "-" + match[2].downcase
  end
  "#{schema_type}-manifest-v#{schema_version}"
end