Class: AdLint::MessageDefinitionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/adlint/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(pkg_name, lang_name) ⇒ MessageDefinitionFile

Returns a new instance of MessageDefinitionFile.



379
380
381
382
# File 'lib/adlint/message.rb', line 379

def initialize(pkg_name, lang_name)
  @package_name  = pkg_name
  @language_name = lang_name
end

Instance Method Details

#read_into(msg_catalog) ⇒ Object



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# 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