<commit_before>/*jslint node: true, nomen: true, es5: true*/

"use strict";
var PostProvider = function () {
    var self = this,
        mongoose = require("mongoose"),
        postSchema = mongoose.Schema({
            body: String,
            tags: Array,
            created:  {
                type: Date,
                default: Date.now
            }
        });

    mongoose.connect("mongodb://localhost/blog-db");
    mongoose.connection.on('error', console.error.bind(console, 'connection error:'));

    self.Post = mongoose.model('Post', postSchema);
};

PostProvider.prototype.allPosts = function (callback) {
    var self = this;

    self.Post.find({}).sort({created: -1}).exec(function (err, posts) {
        if (!err) {
            callback(posts);
        } else {
            callback(err);
        }
    });
};

PostProvider.prototype.savePost = function (post) {
    var self = this,
        newPost = new self.Post(post);

    newPost.save(function (err, newPost) {
        if (err) {
            console.log(err + newPost.title);
        }
    });
};

PostProvider.prototype.deletePost = function (post) {
    var self = this;

    self.Post.remove({ _id:  post._id }, function (err) {
        if (err) {
            console.log(err);
        }
    });
};

exports.PostProvider = PostProvider;<commit_msg>Post provider now checks for production value for mongodb url.<commit_after>/*jslint node: true, nomen: true, es5: true*/

"use strict";
var PostProvider = function () {
    var self = this,
        mongoUrl = process.env.MONGOHQ_URL || "mongodb://localhost/blog-db",
        mongoose = require("mongoose"),
        postSchema = mongoose.Schema({
            body: String,
            tags: Array,
            created:  {
                type: Date,
                default: Date.now
            }
        });

    mongoose.connect(mongoUrl);
    mongoose.connection.on('error', console.error.bind(console, 'connection error:'));

    self.Post = mongoose.model('Post', postSchema);
};

PostProvider.prototype.allPosts = function (callback) {
    var self = this;

    self.Post.find({}).sort({created: -1}).exec(function (err, posts) {
        if (!err) {
            callback(posts);
        } else {
            callback(err);
        }
    });
};

PostProvider.prototype.savePost = function (post) {
    var self = this,
        newPost = new self.Post(post);

    newPost.save(function (err, newPost) {
        if (err) {
            console.log(err + newPost.title);
        }
    });
};

PostProvider.prototype.deletePost = function (post) {
    var self = this;

    self.Post.remove({ _id:  post._id }, function (err) {
        if (err) {
            console.log(err);
        }
    });
};

exports.PostProvider = PostProvider;
{'fraction_non_alphanumeric': 0.1449222985182508, 'fraction_numerical': 0.0014456089627755693, 'mean_word_length': 2.0687361419068737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5784310', 'n_tokens_mistral': 841, 'n_tokens_neox': 831, 'n_words': 177}