class AdLint::MessageDefinitionFile

Constants

MESSAGES_FNAME

Public Class Methods

new(pkg_name, lang_name) click to toggle source
# File lib/adlint/message.rb, line 379
def initialize(pkg_name, lang_name)
  @package_name  = pkg_name
  @language_name = lang_name
end

Public Instance Methods

read_into(msg_catalog) click to toggle source
# File lib/adlint/message.rb, line 384
def read_into(msg_catalog)
  File.open(fpath, "r:utf-8") do |io|
    case ary_or_stream = YAML.load_stream(io)
    when Array
      # NOTE: YAML.load_stream returns Array in Ruby 1.9.3-preview1.
      doc = ary_or_stream.first
    when YAML::Stream
      doc = ary_or_stream.documents.first
    end
    validate_version(doc["version"])
    if msg_def = doc["message_definition"]
      msg_catalog.merge!(@package_name, msg_def)
    else
      raise "invalid form of the message definition file."
    end
  end
  self
end

Private Instance Methods

base_dpath() click to toggle source
# File lib/adlint/message.rb, line 404
def base_dpath
  subclass_responsibility
end
fpath() click to toggle source
# File lib/adlint/message.rb, line 408
def fpath
  base_dpath.join(Pathname.new(@language_name)).join(MESSAGES_FNAME)
end
validate_version(ver) click to toggle source
# File lib/adlint/message.rb, line 412
def validate_version(ver)
  # NOTE: Version field of the message catalog does not mean the schema
  #       version of the catalog file, but a revision number of the catalog
  #       contents.
  #       When AdLint is installed normally, the schema version of the
  #       catalog is always valid.  So, schema version validation is
  #       unnecessary.
end