Commit 01456f32 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Append to external classes inside the overrides processor.

Eliminates a special case code used when calling the overrides
processor.

Added :[]= method to options to allow us setting values. Changed the
implementetion to use idiomatic instance_variable_get/set methods.
parent bfd82170
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -50,8 +50,7 @@ module JsDuck
      Process::Accessors.new(classes_hash).process_all!
      Process::Ext4Events.new(classes_hash, opts).process_all!
      Process::Enums.new(classes_hash).process_all!
      # Ignore override classes after applying them to actual classes
      opts.external_classes += Process::Overrides.new(classes_hash).process_all!
      Process::Overrides.new(classes_hash, opts).process_all!

      classes_hash.values
    end
+4 −1
Original line number Diff line number Diff line
@@ -142,7 +142,10 @@ module JsDuck
    # Make options object behave like hash.
    # This allows us to substitute it with hash in unit tests.
    def [](key)
      send(key)
      instance_variable_get("@#{key}")
    end
    def []=(key, value)
      instance_variable_set("@#{key}", value)
    end

    def parse!(argv)
+7 −5
Original line number Diff line number Diff line
@@ -4,13 +4,15 @@ module JsDuck
  module Process

    class Overrides
      def initialize(classes_hash)
      def initialize(classes_hash, opts = {:external_classes => []})
        @classes_hash = classes_hash
        @opts = opts
      end

      # Applies all override classes to target classes, then deletes the
      # overrides themselves from classes hash.  Returns names of all
      # the processed override classes.
      # Applies all override classes to target classes, then deletes
      # the overrides themselves from classes hash and adds the names
      # of all the processed overrides to external_classes list in
      # options object.
      def process_all!
        overrides = []

@@ -26,7 +28,7 @@ module JsDuck
          @classes_hash.delete(cls[:name])
        end

        overrides.map {|c| c[:name] }
        @opts[:external_classes] += overrides.map {|c| c[:name] }
      end

      private