Skip to content

Commit

Permalink
Merge branch 'refactor-c'
Browse files Browse the repository at this point in the history
  • Loading branch information
caius committed Aug 13, 2012
2 parents 2a4fbf0 + 6d3f58e commit 8daa5cf
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ pkg
tmp
.DS_Store
Makefile
Gemfile.lock
3 changes: 3 additions & 0 deletions Gemfile
@@ -0,0 +1,3 @@
source :rubygems

gemspec
24 changes: 5 additions & 19 deletions Rakefile
@@ -1,21 +1,7 @@
require "rake/extensiontask"
require "rubygems/package_task"

spec = Gem::Specification.new do |s|
s.name = "cuuid"
s.version = "0.3.1"
s.author = "Caius Durling"
s.email = "caius@emberads.com"
s.homepage = "http://github.com/EmberAds/cuuid"
s.platform = Gem::Platform::RUBY
s.summary = "Ruby wrapper for the uuid library in your OS."
s.files = FileList["ext/**/*", "lib/**/*.rb", "[A-Z]*"].to_a
s.extensions = FileList["ext/**/extconf.rb"]

s.add_development_dependency "rake-compiler"
s.add_development_dependency "rspec"
s.has_rdoc = false
end
spec = Gem::Specification.load("cuuid.gemspec")

require "rubygems/package_task"
Gem::PackageTask.new(spec) {}
Rake::ExtensionTask.new('cuuid', spec)

require "rake/extensiontask"
Rake::ExtensionTask.new("cuuid_generator", spec)
15 changes: 15 additions & 0 deletions cuuid.gemspec
@@ -0,0 +1,15 @@
Gem::Specification.new do |s|
s.name = "cuuid"
s.version = "0.3.1"
s.author = "Caius Durling"
s.email = "caius@emberads.com"
s.homepage = "http://github.com/EmberAds/cuuid"
s.platform = Gem::Platform::RUBY
s.summary = "Ruby wrapper for the uuid library in your OS."
s.files = Dir["ext/**/*", "lib/**/*.rb", "[A-Z]*"].to_a
s.extensions = Dir["ext/**/extconf.rb"]

s.add_development_dependency "rake-compiler"
s.add_development_dependency "rspec"
s.has_rdoc = false
end
31 changes: 0 additions & 31 deletions ext/cuuid/cuuid.c

This file was deleted.

5 changes: 0 additions & 5 deletions ext/cuuid/extconf.rb

This file was deleted.

31 changes: 31 additions & 0 deletions ext/cuuid_generator/cuuid_generator.c
@@ -0,0 +1,31 @@
#include <ruby.h>
#include <uuid/uuid.h>

// CUUID::Generator.generate

// Define our module & class constants
VALUE CUUID = Qnil;
VALUE CUUIDGenerator = Qnil;

void Init_cuuid_generator();
static VALUE method_cuuid_generator_generate(VALUE self);

// Define CUUID, CUUID::Generator and the class method
void Init_cuuid_generator() {
CUUID = rb_define_module("CUUID");
CUUIDGenerator = rb_define_module_under(CUUID, "Generator");
rb_define_singleton_method(CUUIDGenerator, "generate", method_cuuid_generator_generate, 0);
}

// Implement CUUID.generate
static VALUE method_cuuid_generator_generate(VALUE self) {
uuid_t uuid_id;
char uuid_str[128];

// Generate UUID and grab string version of it
uuid_generate(uuid_id);
uuid_unparse(uuid_id, uuid_str);

// Cast it into a ruby string and return it
return rb_str_new2(uuid_str);
}
5 changes: 5 additions & 0 deletions ext/cuuid_generator/extconf.rb
@@ -0,0 +1,5 @@
require 'mkmf'

dir_config("cuuid_generator")
have_library("uuid") if RUBY_PLATFORM[/linux/i]
create_makefile("cuuid_generator")
9 changes: 9 additions & 0 deletions lib/cuuid.rb
@@ -0,0 +1,9 @@
require File.expand_path("cuuid_generator", File.dirname(__FILE__))

module CUUID

# backwards compatible (& lazy)
def self.generate
Generator.generate
end
end

0 comments on commit 8daa5cf

Please sign in to comment.