{"size": 1350, "ext": "js", "max_stars_repo_path": "lib/model/MultiOptions.js", "max_stars_repo_name": "gruntjs-updater/grunt-devserver", "max_stars_repo_stars_event_min_datetime": "2015-11-29T18:16:24.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-31T13:43:24.000Z", "max_issues_repo_path": "lib/model/MultiOptions.js", "max_issues_repo_name": "devpaul/grunt-devserver", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/model/MultiOptions.js", "max_forks_repo_name": "devpaul/grunt-devserver", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.0, "max_line_length": 96, "alphanum_fraction": 0.722962963}
var path = require('path')
  , _ = require('underscore')
  , OPTIONS_NAME = 'options'

MultiOptions.prototype.hasConfiguration = hasConfiguration
MultiOptions.prototype.getOptions = getOptions
MultiOptions.prototype.getConfigurationNames = getConfigurationNames
MultiOptions.prototype._loadOptionsFile = loadOptionsFile

/**
 * An options file containing one or more options configuration.  MultiOptions is used for grunt
 * or file based configurations that may have multiple configurations.
 * @param multioptions
 * @constructor
 */
function MultiOptions(multioptions) {
    if(typeof multioptions === 'string')
        multioptions = this._loadOptionsFile(multioptions)

    this.multioptions = multioptions || {}
}

function getOptions(name) {
    var options = _.clone(this.multioptions.options) || {}

    if(name)
        _.extend(options, this.multioptions[name])

    return options
}

function getConfigurationNames() {
    var names = []
      , name

    for(name in this.multioptions)
        if(this.hasConfiguration(name))
            names.push(name)

    return names
}

function hasConfiguration(name) {
    return this.multioptions.hasOwnProperty(name) && name !== OPTIONS_NAME
}

function loadOptionsFile(filename) {
    if(!filename)
        return {}

    return require(path.resolve(filename))
}

module.exports = MultiOptions