Sha256: 7918a5e13614185b9a3eb3b01725ef3894bfeaacc8a44d332f9b2267e7bf3ee3

Contents?: true

Size: 897 Bytes

Versions: 16

Compression:

Stored size: 897 Bytes

Contents

require 'jsduck/util/json'

module JsDuck
  module Options

    # Handles reading JSON config file, specified by --config option.
    class Config

      # Reads JSON configuration from file and returns an array of
      # config options that can be feeded into optparser.
      def self.read(filename)
        config = []
        json = Util::Json.read(filename)
        json.each_pair do |key, value|
          if key == "--"
            # filenames
            config += Array(value).map(&:to_s)
          elsif value == true
            # simple switch
            config += [key.to_s]
          else
            # An option with value or with multiple values.
            # In the latter case, add the option multiple times.
            Array(value).each do |v|
              config += [key.to_s, v.to_s]
            end
          end
        end
        config
      end

    end

  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/options/config.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/options/config.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/options/config.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/options/config.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/options/config.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/options/config.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.10 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.9 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.8 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.7 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.5 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.4 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.3 lib/jsduck/options/config.rb
jsduck-troopjs-0.0.1 lib/jsduck/options/config.rb
jsduck-6.0.0beta lib/jsduck/options/config.rb