// This is a generated file, modify: generate/templates/class_content.cc.
#include <nan.h>
#include <string.h>

extern "C" {
#include <git2.h>
}


#include "../include/functions/copy.h"
#include "../include/macros.h"
#include "../include/ignore.h"

#include "../include/repository.h"

#include <iostream>

using namespace std;
using namespace v8;
using namespace node;


void GitIgnore::InitializeComponent(Handle<v8::Object> target)
{
  NanScope();

  Local<Object> object = NanNew<Object>();

  NODE_SET_METHOD(object, "addRule", AddRule);
  NODE_SET_METHOD(object, "clearInternalRules", ClearInternalRules);

  target->Set(NanNew<String>("Ignore"), object);
}


/*
 * @param Repository repo
   * @param String rules
     * @return Number  result    */
NAN_METHOD(GitIgnore::AddRule)
{
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsObject()) {
    return NanThrowError("Repository repo is required.");
  }

  if (args.Length() == 1 || !args[1]->IsString()) {
    return NanThrowError("String rules is required.");
  }

// start convert_from_v8 block
  git_repository * from_repo;
  from_repo = ObjectWrap::Unwrap<GitRepository>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
// start convert_from_v8 block
  const char * from_rules;

  String::Utf8Value rules(args[1]->ToString());
  from_rules = (const char *) strdup(*rules);
// end convert_from_v8 block
  int result = git_ignore_add_rule(
                 from_repo
                 ,from_rules
               );

  Handle<Value> to;
// start convert_to_v8 block
  to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}

/*
 * @param Repository repo
     * @return Number  result    */
NAN_METHOD(GitIgnore::ClearInternalRules)
{
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsObject()) {
    return NanThrowError("Repository repo is required.");
  }

// start convert_from_v8 block
  git_repository * from_repo;
  from_repo = ObjectWrap::Unwrap<GitRepository>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  int result = git_ignore_clear_internal_rules(
                 from_repo
               );

  Handle<Value> to;
// start convert_to_v8 block
  to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
Persistent<Function> GitIgnore::constructor_template;
