Method: OSAX::ScriptingAddition#initialize

Defined in:
lib/osax.rb

#initialize(name, terms = nil) ⇒ ScriptingAddition

Represents a single scripting addition.



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/osax.rb', line 523

def initialize(name, terms=nil)
  # name: string -- a scripting addition's name, e.g. "StandardAdditions";
  # basically its filename minus the '.osax' suffix
  #
  # terms : module or nil -- an optional terminology glue module,
  # as exported by Terminology.dump; if given, ScriptingAddition
  # will use this instead of retrieving the terminology dynamically
  #
  # Note that name is case-insensitive and an '.osax' suffix is ignored if given.
  @_osax_name = name
  if not terms
    osax_name = name.downcase.sub(/(?i)\.osax$/, '')
    OSAX._init_caches if OSAXCache == {}
    path, terminology_tables = OSAXCache[osax_name]
    if not path
      raise ArgumentError, "Scripting addition not found: #{name.inspect}"
    end
    if not terminology_tables
      sp = OSAX::SdefParser.new
      sp.parse_file(path)
      if osax_name == 'standardadditions'
        OSAX::StandardAdditionsEnums.each { |o| sp.enumerators.push(o)}
      end
      terminology_tables = Terminology.tables_for_parsed_sdef(sp)
      OSAXCache[osax_name][1] = terminology_tables
    end
    @_terms = terminology_tables
    terms = OSAXData.new(:current, nil, @_terms)
  elsif not terms.is_a?(OSAX::OSAXData) # assume it's a glue module
    terminology_tables = Terminology.tables_for_module(terms)
    @_terms = terminology_tables
    terms = OSAXData.new(:current, nil, @_terms)
  end
  super(terms, AEM.app)
end