From 01456f32526bd53bb84e8284798f7d61bdb6e3d3 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Mon, 28 Jan 2013 19:05:44 +0200 Subject: [PATCH] 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. --- lib/jsduck/batch_processor.rb | 3 +-- lib/jsduck/options.rb | 5 ++++- lib/jsduck/process/overrides.rb | 12 +++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/jsduck/batch_processor.rb b/lib/jsduck/batch_processor.rb index beaf2418..6ae16536 100644 --- a/lib/jsduck/batch_processor.rb +++ b/lib/jsduck/batch_processor.rb @@ -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 diff --git a/lib/jsduck/options.rb b/lib/jsduck/options.rb index ae8f59c6..1adf53e8 100644 --- a/lib/jsduck/options.rb +++ b/lib/jsduck/options.rb @@ -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) diff --git a/lib/jsduck/process/overrides.rb b/lib/jsduck/process/overrides.rb index 753a55f2..6af8ee2f 100644 --- a/lib/jsduck/process/overrides.rb +++ b/lib/jsduck/process/overrides.rb @@ -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 -- GitLab