From 30d633cf096f8b11c1b27eeee08967a3e92cd832 Mon Sep 17 00:00:00 2001 From: Alex Young Date: Mon, 16 May 2011 11:29:07 +0100 Subject: [PATCH] Add a gemspec and support loading ffi as a gem --- Rakefile | 12 +++++++++--- lib/linux/iptables.rb | 8 +++++++- lib/linux/sendmsg.rb | 7 ++++++- netlinkrb.gemspec | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 netlinkrb.gemspec diff --git a/Rakefile b/Rakefile index 55acae1..44924b7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,12 @@ +require 'rake/testtask' + ROOT = File.dirname(__FILE__) -task :test do - $:.unshift File.join(ROOT, "lib") - $:.unshift File.join(ROOT, "test") +Rake::TestTask.new do |t| + t.verbose = true + t.test_files = FileList["test/**/t_*.rb"] +end + +task :gem do + sh "gem build netlinkrb.gemspec" end diff --git a/lib/linux/iptables.rb b/lib/linux/iptables.rb index a504367..bf8e056 100644 --- a/lib/linux/iptables.rb +++ b/lib/linux/iptables.rb @@ -1,6 +1,12 @@ require 'socket' require 'linux/constants' -require 'ffi' + +begin + require 'ffi' +rescue LoadError + require('rubygems') ? retry : raise +end + # Good things about FFI::Struct: # - robust pre-existing code diff --git a/lib/linux/sendmsg.rb b/lib/linux/sendmsg.rb index 4f30d9e..b84a7d8 100644 --- a/lib/linux/sendmsg.rb +++ b/lib/linux/sendmsg.rb @@ -1,8 +1,13 @@ # Patchup to add Socket#sendmsg and Socket#recvmsg for ruby 1.8 if BasicSocket.instance_methods.grep(/^sendmsg$/).empty? - require 'ffi' + begin + require 'ffi' + rescue LoadError + require('rubygems') ? retry : raise + end + class BasicSocket module FFIExt extend FFI::Library diff --git a/netlinkrb.gemspec b/netlinkrb.gemspec new file mode 100644 index 0000000..1508803 --- /dev/null +++ b/netlinkrb.gemspec @@ -0,0 +1,17 @@ +# encoding: utf-8 + +lib = File.expand_path("../lib", __FILE__) +$:.unshift lib unless $:.include? lib + +Gem::Specification.new do |s| + s.name = "netlinkrb" + s.version = "0.10" + s.platform = Gem::Platform::RUBY + s.authors = ["Brian Candler", "Patrick Cherry", "Alex Young"] + s.email = ["matthew@bytemark.co.uk"] + s.summary = "Interface to Linux' Netlink API" + s.description = "Ruby native interface to the Netlink API which avoids shelling out to command-line tools as much as possible." + s.files = Dir["{lib,examples}/**/*"] + %w{README} + s.require_path = "lib" + s.add_dependency "ffi" +end