Permalink
Browse files

Gem cleanup and refactoring. Bump version to 0.4.0.

  • Loading branch information...
1 parent 65b454d commit cb966268d2701fa08b8410cb67538a71b33babcc @matiaskorhonen committed May 17, 2010
Showing with 164 additions and 161 deletions.
  1. +7 −1 .gitignore
  2. +9 −0 Gemfile
  3. +9 −50 Rakefile
  4. +0 −1 VERSION
  5. +2 −3 bin/wol
  6. +2 −1 lib/wol.rb
  7. +90 −95 lib/wol/runner.rb
  8. +3 −0 lib/wol/version.rb
  9. +1 −1 spec/parsefile_spec.rb
  10. +0 −1 spec/spec.opts
  11. +8 −7 spec/spec_helper.rb
  12. +5 −1 spec/wakeonlan_spec.rb
  13. +28 −0 wol.gemspec
View
@@ -13,10 +13,16 @@ tmtags
## VIM
*.swp
+## Other editors
+.idea
+tags
+
## PROJECT::GENERAL
coverage
rdoc
pkg
+.bundle
+*.gem
## PROJECT::SPECIFIC
-.idea
+
View
@@ -0,0 +1,9 @@
+source "http://rubygems.org"
+
+# Will automatically pull in this gem and all its
+# dependencies specified in the gemspec
+gem "wol", :path => File.expand_path("..", __FILE__)
+
+# These are development dependencies
+gem "rake"
+gem "rspec", "2.0.0.beta.8"
View
@@ -1,55 +1,14 @@
-require 'rubygems'
-require 'rake'
+require "bundler"
+Bundler.setup
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "wol"
- gem.summary = %Q{Ruby WoL}
- gem.description = %Q{Ruby Wake-On-LAN}
- gem.email = "korhonen.matt@gmail.com"
- gem.homepage = "http://github.com/k33l0r/wol"
- gem.authors = ["Matias Korhonen"]
- gem.rubyforge_project = 'wol'
- gem.add_development_dependency "rspec", ">= 0"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
-end
-
-require 'spec/rake/spectask'
-Spec::Rake::SpecTask.new(:spec) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-Spec::Rake::SpecTask.new(:rcov) do |spec|
- spec.libs << 'lib' << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
-end
-
-task :spec => :check_dependencies
-
-task :default => :spec
+require "rspec/core/rake_task"
+Rspec::Core::RakeTask.new(:spec)
-require 'rake/rdoctask'
-gem 'rdoc'
-require 'rdoc/rdoc'
+gemspec = eval(File.read("wol.gemspec"))
-Rake::RDocTask.new do |rdoc|
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
+task :build => "#{gemspec.full_name}.gem"
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "Ruby Wake-On-LAN #{version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('COPYING')
- rdoc.rdoc_files.include('LICENSE')
- rdoc.rdoc_files.include('lib/**/*.rb')
-
- rdoc.options += [
- '-HN',
- '-f', 'darkfish',
- ]
+file "#{gemspec.full_name}.gem" => gemspec.files + ["wol.gemspec"] do
+ system "gem build wol.gemspec"
+ system "gem install wol-#{Wol::VERSION}.gem"
end
View
@@ -1 +0,0 @@
-0.3.3
View
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
-
require 'wol'
+wol = Wol::Runner.new
-exit Wol::Runner.run!(ARGV)
+exit wol.run(ARGV)
View
@@ -1,3 +1,4 @@
require 'wol/wakeonlan'
require 'wol/runner'
-require 'wol/parsefile'
+require 'wol/parsefile'
+require 'wol/version'
View
@@ -5,10 +5,9 @@
#
require 'optparse'
-module Wol
- # Run the Ruby-Wake-On-LAN command, +wol+, and parse the given options
- module Runner
- @sample_file = %{# File structure
+# Run the Ruby-Wake-On-LAN command, +wol+, and parse the given options
+class Wol::Runner
+ @sample_file = %{# File structure
# --------------
# - blank lines are ignored
# - comment lines are ignored (lines starting with a hash mark '#')
@@ -27,132 +26,128 @@ module Runner
07:09:09:0A:0B:0C example.com
0D:0E:0F:00:10:11}
+ def initialize
@options = { :quiet => false,
:address => "255.255.255.255",
:port => 9,
:delay => 0.01,
:count => 3,
:macs => [],
:file => nil,
- :nothing_to_wake => false}
-
- # Parse the give arguments
- def self.parse!(args)
- args = ["-h"] if args.empty?
+ :nothing_to_wake => false }
+ end
- opts = OptionParser.new do |opts|
- # Set a banner, displayed at the top
- # of the help screen.
- opts.banner = "Ruby Wake-On-LAN #{version}\nUsage: wol -i ADDRESS ff:ff:ff:ff:ff:ff"
+ # Parse the give arguments
+ def parse!(args)
+ args = ["-h"] if args.empty?
- opts.separator "\nSpecific options:"
+ opts = OptionParser.new do |opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
+ opts.banner = "Ruby Wake-On-LAN #{Wol::VERSION}\nUsage: wol -i ADDRESS ff:ff:ff:ff:ff:ff"
- opts.on( '-q', '--quiet', 'No console output' ) do
- @options[:quiet] = true
- end
+ opts.separator "\nSpecific options:"
- opts.on( '-i', '--address 255.255.255.255', 'Set the destination address' ) do |address|
- @options[:address] = address
- end
+ opts.on( '-q', '--quiet', 'No console output' ) do
+ @options[:quiet] = true
+ end
- opts.on( '-p', '--port 9', Integer, 'Set the destination port' ) do |port|
- @options[:port] = port
- end
+ opts.on( '-i', '--address 255.255.255.255', 'Set the destination address' ) do |address|
+ @options[:address] = address
+ end
- opts.on( '-d', '--delay 0.01', Float, 'Delay between sending packets in seconds') do |delay|
- @options[:delay] = delay
- end
+ opts.on( '-p', '--port 9', Integer, 'Set the destination port' ) do |port|
+ @options[:port] = port
+ end
- opts.on( '-c', '--count 3', Integer, 'Number of packets to send. Default 3') do |count|
- @options[:count] = count
- end
+ opts.on( '-d', '--delay 0.01', Float, 'Delay between sending packets in seconds') do |delay|
+ @options[:delay] = delay
+ end
- opts.on( '-f', '--file FILE', 'TODO: Uses a file as a source of addresses') do |file|
- @options[:file] = file
- end
+ opts.on( '-c', '--count 3', Integer, 'Number of packets to send. Default 3') do |count|
+ @options[:count] = count
+ end
- opts.separator "\nCommon options:"
+ opts.on( '-f', '--file FILE', 'TODO: Uses a file as a source of addresses') do |file|
+ @options[:file] = file
+ end
- opts.on_tail( '-h', '--help', 'Display this message' ) do
- @options[:nothing_to_wake] = true
- puts opts
- end
+ opts.separator "\nCommon options:"
- opts.on_tail( '-s', '--sample-file', 'Display a sample file') do
- @options[:nothing_to_wake] = true
- puts @sample_file
- end
+ opts.on_tail( '-h', '--help', 'Display this message' ) do
+ @options[:nothing_to_wake] = true
+ puts opts
+ end
- opts.on_tail( '-v', '--version', 'Show version') do
- @options[:nothing_to_wake] = true
- puts "Ruby Wake-On-LAN #{version}"
- end
+ opts.on_tail( '-s', '--sample-file', 'Display a sample file') do
+ @options[:nothing_to_wake] = true
+ puts @sample_file
end
- begin
- opts.parse!(args)
+ opts.on_tail( '-v', '--version', 'Show version') do
+ @options[:nothing_to_wake] = true
+ puts "Ruby Wake-On-LAN #{Wol::VERSION}"
+ end
+ end
- if @options[:file].nil?
- args.each do |arg|
- @options[:macs] << arg if /^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/.match(arg)
- end
+ begin
+ opts.parse!(args)
- @options[:macs].uniq!
+ if @options[:file].nil?
+ args.each do |arg|
+ @options[:macs] << arg if /^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/.match(arg)
end
- return @options
- rescue OptionParser::InvalidOption => e
- STDERR.puts e.message, "\n", opts
- return -1
+ @options[:macs].uniq!
end
- end
- # Return the version from the VERSION file if it exists
- def self.version
- File.exist?('VERSION') ? File.read('VERSION') : ""
+ return @options
+ rescue OptionParser::InvalidOption => e
+ STDERR.puts e.message, "\n", opts
+ return -1
end
+ end
- # Send WOL MagicPackets based on the parsed options
- def self.wake!
- if @options[:file]
- hosts = ParseFile.read_and_parse_file(@options[:file])
+ # Send WOL MagicPackets based on the parsed options
+ def wake
+ if @options[:file]
+ hosts = ParseFile.read_and_parse_file(@options[:file])
- hosts.each do |host|
- @options[:address], @options[:macs], @options[:port] = host[:address], host[:mac], host[:port]
+ hosts.each do |host|
+ @options[:address], @options[:macs], @options[:port] = host[:address], host[:mac], host[:port]
- message = WakeOnLan.new(@options).wake.to_s
- puts message unless options[:quiet]
-
- return 0
- end
- elsif !@options[:macs].empty?
- @options[:macs].each do |mac|
- @options[:mac] = mac
- message = WakeOnLan.new(@options).wake.to_s
- puts message unless @options[:quiet]
- end
+ message = WakeOnLan.new(@options).wake.to_s
+ puts message unless options[:quiet]
return 0
- elsif @options[:macs].empty? && @options[:file].nil? && !@options[:nothing_to_wake]
- raise Exception, "You must supply a MAC address or a file"
- else
- return -1
end
- end
-
- # Parse the command line options, then use them to wake up any given hosts.
- def self.run!(argv)
- begin
- parse!(argv)
-
- return wake!
- rescue SocketError => e
- puts e.message
- return -1
- rescue Exception => e
- STDERR.puts e.message
- return -1
+ elsif !@options[:macs].empty?
+ @options[:macs].each do |mac|
+ @options[:mac] = mac
+ message = WakeOnLan.new(@options).wake.to_s
+ puts message unless @options[:quiet]
end
+
+ return 0
+ elsif @options[:macs].empty? && @options[:file].nil? && !@options[:nothing_to_wake]
+ raise Exception, "You must supply a MAC address or a file"
+ else
+ return -1
end
end
+
+ # Parse the command line options, then use them to wake up any given hosts.
+ def run(argv)
+ begin
+ parse!(argv)
+
+ return wake
+ rescue SocketError => e
+ puts e.message
+ return -1
+ rescue Exception => e
+ STDERR.puts e.message
+ return -1
+ end
+ end
end
View
@@ -0,0 +1,3 @@
+module Wol
+ VERSION = "0.4.0"
+end
@@ -1,4 +1,4 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require "spec_helper"
EXPECTED = [{:port=>9, :mac=>"01:02:03:04:05:06", :address=>"192.168.1.255"},
{:port=>12, :mac=>"01:02:03:04:05:06", :address=>"192.168.2.230"},
View
@@ -1 +0,0 @@
---color
View
@@ -1,9 +1,10 @@
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-require 'wol'
-require 'spec'
-require 'spec/autorun'
+require "rubygems"
+require "bundler"
+Bundler.setup
-Spec::Runner.configure do |config|
+require "rspec"
+require "wol"
+
+Rspec.configure do |config|
-end
+end
@@ -1,4 +1,4 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+require "spec_helper"
describe "Wake-On-LAN" do
it "should send a MagicPacket to the broadcast addresses" do
@@ -24,4 +24,8 @@
it "should return nil if quiet is set to true" do
Wol::WakeOnLan.new(:quiet => true).wake.should == nil
end
+
+ it "should return the version number as a string" do
+ Wol::VERSION.class.should == String
+ end
end
Oops, something went wrong. Retry.

0 comments on commit cb96626

Please sign in to comment.