sysuuid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,15 @@
1
+ SYNOPSIS
2
+ $ gem install sysuuid
3
+ irb> require 'sysuuid'
4
+ irb> sysuuid #=> "4b7067bd-928b-4656-9960-8a58edc6ff02"
5
+ irb> sysuuid #=> "3cb722b9-7776-4198-bdd2-dcd228716658"
6
+
7
+ DESCRIPTION
8
+ Uses uuid_generate from e2fsprogs, which comes standard
9
+ with OS X and Linux.
10
+
11
+ It's over 2000 times faster than shelling out to uuidgen.
12
+
13
+ AVAILABILITY
14
+ http://github.com/dsturnbull/sysuuid
15
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'vendor/gems/environment'
2
+
3
+ require 'rake'
4
+ require 'spec'
5
+ require 'spec/rake/spectask'
6
+
7
+ task :default => [:clean, :make, :spec]
8
+
9
+ task :make do
10
+ Dir.chdir 'ext' do
11
+ puts `ruby extconf.rb`
12
+ puts `make`
13
+ end
14
+ end
15
+
16
+ Spec::Rake::SpecTask.new(:spec) do |t|
17
+ t.spec_opts = %w(-fs -c)
18
+ t.spec_files = FileList['spec/*_spec.rb']
19
+ end
20
+
21
+ task :clean do
22
+ `rm -r ext/*.o ext/*.so ext/*.bundle ext/conftest.dSYM 2>/dev/null`
23
+ end
24
+
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |s|
27
+ s.name = 'sysuuid'
28
+ s.summary = 'uses uuid.h for fast uuid generation'
29
+ s.email = 'dsturnbull@me.com'
30
+ s.homepage = 'http://github.com/dsturnbull/sysuuid'
31
+ s.description =<<-eod
32
+ sysuuid # => BBC4937C-344F-47C5-AA36-E19CC070DBCC
33
+ eod
34
+ s.executables = []
35
+ s.authors = ['David Turnbull']
36
+ s.files = ['Rakefile', 'ext/sysuuid.c', 'ext/extconf.rb', 'ext/Makefile']
37
+ end
data/ext/Makefile ADDED
@@ -0,0 +1,157 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir):$(topdir):$(hdrdir)
10
+ exec_prefix = $(prefix)
11
+ prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
12
+ sharedstatedir = $(prefix)/com
13
+ mandir = $(DESTDIR)/usr/share/man
14
+ psdir = $(docdir)
15
+ oldincludedir = $(DESTDIR)/usr/include
16
+ localedir = $(datarootdir)/locale
17
+ bindir = $(exec_prefix)/bin
18
+ libexecdir = $(exec_prefix)/libexec
19
+ sitedir = $(DESTDIR)/Library/Ruby/Site
20
+ htmldir = $(docdir)
21
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
22
+ includedir = $(prefix)/include
23
+ infodir = $(DESTDIR)/usr/share/info
24
+ vendorlibdir = $(vendordir)/$(ruby_version)
25
+ sysconfdir = $(prefix)/etc
26
+ libdir = $(exec_prefix)/lib
27
+ sbindir = $(exec_prefix)/sbin
28
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
29
+ docdir = $(datarootdir)/doc/$(PACKAGE)
30
+ dvidir = $(docdir)
31
+ vendordir = $(libdir)/ruby/vendor_ruby
32
+ datarootdir = $(prefix)/share
33
+ pdfdir = $(docdir)
34
+ archdir = $(rubylibdir)/$(arch)
35
+ sitearchdir = $(sitelibdir)/$(sitearch)
36
+ datadir = $(datarootdir)
37
+ localstatedir = $(prefix)/var
38
+ sitelibdir = $(sitedir)/$(ruby_version)
39
+
40
+ CC = gcc
41
+ LIBRUBY = $(LIBRUBY_SO)
42
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
43
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
44
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
45
+
46
+ RUBY_EXTCONF_H =
47
+ CFLAGS = -fno-common -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common $(cflags) -Werror -Wall
48
+ INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
49
+ DEFS =
50
+ CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
51
+ CXXFLAGS = $(CFLAGS)
52
+ ldflags = -L. -arch x86_64
53
+ dldflags =
54
+ archflag =
55
+ DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
56
+ LDSHARED = cc -arch x86_64 -pipe -bundle -undefined dynamic_lookup
57
+ AR = ar
58
+ EXEEXT =
59
+
60
+ RUBY_INSTALL_NAME = ruby
61
+ RUBY_SO_NAME = ruby
62
+ arch = universal-darwin10.0
63
+ sitearch = universal-darwin10.0
64
+ ruby_version = 1.8
65
+ ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
66
+ RUBY = $(ruby)
67
+ RM = rm -f
68
+ MAKEDIRS = mkdir -p
69
+ INSTALL = /usr/bin/install -c
70
+ INSTALL_PROG = $(INSTALL) -m 0755
71
+ INSTALL_DATA = $(INSTALL) -m 644
72
+ COPY = cp
73
+
74
+ #### End of system configuration section. ####
75
+
76
+ preload =
77
+
78
+ libpath = . $(libdir)
79
+ LIBPATH = -L. -L$(libdir)
80
+ DEFFILE =
81
+
82
+ CLEANFILES = mkmf.log
83
+ DISTCLEANFILES =
84
+
85
+ extout =
86
+ extout_prefix =
87
+ target_prefix =
88
+ LOCAL_LIBS =
89
+ LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl
90
+ SRCS = sysuuid.c
91
+ OBJS = sysuuid.o
92
+ TARGET = sysuuid
93
+ DLLIB = $(TARGET).bundle
94
+ EXTSTATIC =
95
+ STATIC_LIB =
96
+
97
+ BINDIR = $(bindir)
98
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
99
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
100
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
101
+
102
+ TARGET_SO = $(DLLIB)
103
+ CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
104
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
105
+
106
+ all: $(DLLIB)
107
+ static: $(STATIC_LIB)
108
+
109
+ clean:
110
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
111
+
112
+ distclean: clean
113
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
114
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
115
+
116
+ realclean: distclean
117
+ install: install-so install-rb
118
+
119
+ install-so: $(RUBYARCHDIR)
120
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
121
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
122
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
123
+ install-rb: pre-install-rb install-rb-default
124
+ install-rb-default: pre-install-rb-default
125
+ pre-install-rb: Makefile
126
+ pre-install-rb-default: Makefile
127
+ $(RUBYARCHDIR):
128
+ $(MAKEDIRS) $@
129
+
130
+ site-install: site-install-so site-install-rb
131
+ site-install-so: install-so
132
+ site-install-rb: install-rb
133
+
134
+ .SUFFIXES: .c .m .cc .cxx .cpp .C .o
135
+
136
+ .cc.o:
137
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
138
+
139
+ .cxx.o:
140
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
141
+
142
+ .cpp.o:
143
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
144
+
145
+ .C.o:
146
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
147
+
148
+ .c.o:
149
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
150
+
151
+ $(DLLIB): $(OBJS) Makefile
152
+ @-$(RM) $@
153
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
154
+
155
+
156
+
157
+ $(OBJS): ruby.h defines.h
data/ext/extconf.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'mkmf'
2
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
3
+
4
+ extension_name = 'sysuuid'
5
+ dir_config(extension_name)
6
+
7
+ $CFLAGS += ' -Werror -Wall'
8
+
9
+ create_makefile(extension_name)
data/ext/sysuuid.c ADDED
@@ -0,0 +1,46 @@
1
+ #include "ruby.h"
2
+ #include <uuid/uuid.h>
3
+
4
+ // SysUUID prototypes
5
+ VALUE sysuuid = Qnil;
6
+ VALUE sysuuid_uuid(VALUE self);
7
+
8
+ // other protoypes
9
+ void err(const char *err);
10
+
11
+ // Init_sysuuid - initialize the extension
12
+ void
13
+ Init_sysuuid()
14
+ {
15
+ // class definition - dummy
16
+ sysuuid = rb_define_class("SysUUID", rb_cObject);
17
+
18
+ // instance methods
19
+ rb_define_method(rb_cObject, "sysuuid", sysuuid_uuid, 0);
20
+ }
21
+
22
+ // sysuuid - return a uuid string
23
+ VALUE
24
+ sysuuid_uuid(VALUE self)
25
+ {
26
+ char uuid_str[37];
27
+ uuid_t uuid;
28
+
29
+ uuid_generate(uuid);
30
+ uuid_unparse_lower(uuid, uuid_str);
31
+
32
+ return rb_str_new2(uuid_str);
33
+ }
34
+
35
+ // magic_fail - raise exceptions
36
+ void
37
+ err(const char *error)
38
+ {
39
+ const char *format = "magic_%s() error";
40
+ char *error_message;
41
+
42
+ error_message = malloc(sizeof(char *) * (strlen(format) + strlen(error)));
43
+ sprintf((char *)error_message, format, error);
44
+ rb_raise(rb_const_get(rb_cObject, rb_intern("RuntimeError")), error_message);
45
+ }
46
+
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'should_be_faster'
3
+ require 'tempfile'
4
+ require 'ext/sysuuid'
5
+
6
+ describe SysUUID do
7
+ it 'should create a uuid' do
8
+ sysuuid.should be_instance_of String
9
+ end
10
+
11
+ it 'should create unique uuids' do
12
+ sysuuid.should_not == sysuuid
13
+ end
14
+
15
+ it 'should not repeat for reasonable counts' do
16
+ 1000.times.map { sysuuid }.uniq.length.should == 1000
17
+ end
18
+
19
+ it 'should be faster than `uuidgen`' do
20
+ shell = lambda { `uuidgen` }
21
+ ext = lambda { sysuuid }
22
+ ext.should be_at_least(2000).times.faster_than(shell)
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sysuuid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - David Turnbull
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-11 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " sysuuid # => BBC4937C-344F-47C5-AA36-E19CC070DBCC\n"
22
+ email: dsturnbull@me.com
23
+ executables: []
24
+
25
+ extensions:
26
+ - ext/extconf.rb
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - Rakefile
31
+ - ext/Makefile
32
+ - ext/extconf.rb
33
+ - ext/sysuuid.c
34
+ - README
35
+ has_rdoc: true
36
+ homepage: http://github.com/dsturnbull/sysuuid
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.6
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: uses uuid.h for fast uuid generation
65
+ test_files:
66
+ - spec/sysuuid_spec.rb