// Generated by CoffeeScript 1.3.3
(function() {
  var Bone, TastyBone;

  window.TastyBone = {};

  TastyBone = window.TastyBone;

  Bone = (function() {

    Bone.prototype.collections = {};

    function Bone(original_url, options) {
      var _this = this;
      this.original_url = original_url;
      _.extend(this, Backbone.Events);
      options = options || {};
      jQuery.get(this.original_url, options, function(endpoints) {
        _.each(endpoints, function(endpoint, name) {
          var capitalizedName, model, next_collection;
          if (name[0] === '_') {
            return;
          }
          capitalizedName = name[0].toUpperCase() + name.slice(1);
          model = TastyBone.Model.factory(endpoint.list_endpoint, _this);
          next_collection = TastyBone.Collection.factory(model, endpoint.list_endpoint);
          return _this.collections[capitalizedName + 'Collection'] = next_collection;
        });
        return _this.trigger('ready', _this);
      });
    }

    return Bone;

  })();

  TastyBone.Bone = Bone;

}).call(this);
// Generated by CoffeeScript 1.3.3
(function() {
  var TastyPieModel,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  TastyPieModel = (function(_super) {

    __extends(TastyPieModel, _super);

    function TastyPieModel() {
      return TastyPieModel.__super__.constructor.apply(this, arguments);
    }

    TastyPieModel.prototype.url = function() {
      var url;
      url = Backbone.Model.prototype.url.call(this);
      if (url[url.length - 1] !== '/') {
        url = url + '/';
      }
      return url;
    };

    TastyPieModel.factory = function(endpoint, bone) {
      var AutoTastyPieModel;
      return AutoTastyPieModel = (function(_super1) {

        __extends(AutoTastyPieModel, _super1);

        function AutoTastyPieModel() {
          return AutoTastyPieModel.__super__.constructor.apply(this, arguments);
        }

        AutoTastyPieModel.prototype.initialize = function() {
          return this.urlRoot = endpoint;
        };

        return AutoTastyPieModel;

      })(TastyPieModel);
    };

    return TastyPieModel;

  })(Backbone.Model);

  window.TastyBone.Model = TastyPieModel;

}).call(this);
// Generated by CoffeeScript 1.3.3
(function() {
  var TastyPieCollection,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  TastyPieCollection = (function(_super) {

    __extends(TastyPieCollection, _super);

    function TastyPieCollection() {
      return TastyPieCollection.__super__.constructor.apply(this, arguments);
    }

    TastyPieCollection.prototype.parse = function(data) {
      if ((data != null) && (data.meta != null)) {
        this.meta = data.meta;
      }
      return data.objects || data;
    };

    TastyPieCollection.factory = function(model, endpoint) {
      var AutoTastyPieCollection;
      return AutoTastyPieCollection = (function(_super1) {

        __extends(AutoTastyPieCollection, _super1);

        function AutoTastyPieCollection() {
          return AutoTastyPieCollection.__super__.constructor.apply(this, arguments);
        }

        AutoTastyPieCollection.prototype.model = model;

        AutoTastyPieCollection.prototype.url = endpoint;

        return AutoTastyPieCollection;

      })(TastyPieCollection);
    };

    return TastyPieCollection;

  })(Backbone.Collection);

  window.TastyBone.Collection = TastyPieCollection;

}).call(this);
