/*!
 * options-cache <https://github.com/jonschlinkert/options-cache>
 *
 * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.
 * Licensed under the MIT license.
 */

'use strict';

var typeOf = require('kind-of');


/**
 * Create a new instance of `Options`.
 *
 * **Example:**
 *
 * ```js
 * var util = require('util');
 * var Options = require('options-cache');
 *
 * function App(options) {
 *   Options.call(this, options);
 * }
 * util.inherits(App, Options);
 *
 * App.prototype.a = function(value) {
 *   this.enable(value);
 * };
 *
 * App.prototype.b = function(value) {
 *   if (this.enabled(value)) {
 *     // do something
 *   }
 * };
 * ```
 *
 * @param {Object} `options` Initialize with default options.
 * @api public
 */

var Options = module.exports = function(options) {
  this.options = options || {};
};


/**
 * Set or get an option.
 *
 * ```js
 * app.option('a', true);
 * app.option('a');
 * //=> true
 * ```
 *
 * @param {String} `key` The option name.
 * @param {*} `value` The value to set.
 * @return {*} Returns a `value` when only `key` is defined.
 * @api public
 */

Options.prototype.option = function(key, value) {
  var args = [].slice.call(arguments);

  if (args.length === 1 && typeOf(key) === 'string') {
    return this.options[key];
  }

  if (typeOf(key) === 'object') {
    extend.apply(extend, [this.options].concat(args));
    return this;
  }

  this.options[key] = value;
  return this;
};


/**
 * Check if `key` is enabled (truthy).
 *
 * ```js
 * app.enabled('a');
 * //=> false
 *
 * app.enable('a');
 * app.enabled('a');
 * //=> true
 * ```
 *
 * @param {String} `key`
 * @return {Boolean}
 * @api public
 */

Options.prototype.enabled = function(key) {
  return !!this.option(key);
};


/**
 * Check if `key` is disabled (falsey).
 *
 * ```js
 * app.disabled('a');
 * //=> true
 *
 * app.enable('a');
 * app.disabled('a');
 * //=> false
 * ```
 *
 * @param {String} `key`
 * @return {Boolean} Returns true if `key` is disabled.
 * @api public
 */

Options.prototype.disabled = function(key) {
  return !this.option(key);
};


/**
 * Enable `key`.
 *
 * **Example**
 *
 * ```js
 * app.enable('a');
 * ```
 *
 * @param {String} `key`
 * @return {Object} `Options`to enable chaining
 * @api public
 */

Options.prototype.enable = function(key) {
  return this.option(key, true);
};


/**
 * Disable `key`.
 *
 * **Example**
 *
 * ```js
 * app.disable('a');
 * ```
 *
 * @param {String} `key` The option to disable.
 * @return {Object} `Options`to enable chaining
 * @api public
 */

Options.prototype.disable = function(key) {
  return this.option(key, false);
};


/**
 * Extend the target `obj` with properties from other
 * objects.
 *
 * @param  {Object}  `obj` The target object. Pass an empty object to shallow clone.
 * @param  {Objects}
 * @return {Object}
 * @api private
 */

function extend(o) {
  var args = [].slice.call(arguments, 1);
  if (o == null) {
    return {};
  }
  var len = args.length;

  for (var i = 0; i < len; i++) {
    var obj = args[i];

    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        o[key] = obj[key];
      }
    }
  }
  return o;
}

@@ -222,17 +222,55 @@
 d-of');%0A
+var merge = require('lodash')._.merge;
 %0A
-
 %0A/**%0A * 
@@ -1369,27 +1369,25 @@
     
-extend
+merge
 .apply(
-extend
+merge
 , %5Bt
@@ -1765,10 +1765,16 @@
 urn 
-!!
+Boolean(
 this
@@ -1772,36 +1772,38 @@
 lean(this.option
-(
+s%5B
 key
+%5D
 );%0A%7D;%0A%0A%0A/**%0A * C
@@ -2110,16 +2110,24 @@
 return !
+Boolean(
 this.opt
@@ -2129,20 +2129,22 @@
 s.option
-(
+s%5B
 key
+%5D
 );%0A%7D;%0A%0A%0A
@@ -2683,533 +2683,4 @@
 %7D;%0A%0A
-%0A/**%0A * Extend the target %60obj%60 with properties from other%0A * objects.%0A *%0A * @param  %7BObject%7D  %60obj%60 The target object. Pass an empty object to shallow clone.%0A * @param  %7BObjects%7D%0A * @return %7BObject%7D%0A * @api private%0A */%0A%0Afunction extend(o) %7B%0A  var args = %5B%5D.slice.call(arguments, 1);%0A  if (o == null) %7B%0A    return %7B%7D;%0A  %7D%0A  var len = args.length;%0A%0A  for (var i = 0; i %3C len; i++) %7B%0A    var obj = args%5Bi%5D;%0A%0A    for (var key in obj) %7B%0A      if (obj.hasOwnProperty(key)) %7B%0A        o%5Bkey%5D = obj%5Bkey%5D;%0A      %7D%0A    %7D%0A  %7D%0A  return o;%0A%7D%0A

update how options are enabled/disabled