ok_gntpd 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35988632f70d1087039651f1d336c2950479640d
4
+ data.tar.gz: 2685c3139a0549ea63eff0ff1299b7bec0256b2f
5
+ SHA512:
6
+ metadata.gz: 7d566f401492ab250e025d1308c5701f419937e894596b27f8911fe3e020c13b2f7e93fccd467fb505700398c0dd85a9ecbfac1bb7e6bcdf32d70ed69343c02e
7
+ data.tar.gz: a02f67257a728c51438b6e7e62775b7438087c02f3edccc626da3a1fcf948f5e3266bf0a7b133f45b2f7f15ac8b73b5975f61e5c151d4884bf1677e62ae85765
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ *.swp
19
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+
6
+ desc "Run all specs in spec directory"
7
+ RSpec::Core::RakeTask.new(:spec)
data/bin/ok_gntpd CHANGED
@@ -1,35 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
- # coding: utf-8
3
2
 
4
- require 'optparse'
5
- require 'socket'
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "optparse"
6
+ require "ok_gntpd"
6
7
 
7
8
  # This code is originated from:
8
9
  # http://d.hatena.ne.jp/snaka72/20090614/1244986772
9
10
 
10
- args = {}
11
+ options = {}
11
12
  OptionParser.new do |op|
12
- op.on('-p', '--port PORT') { |v| args[:port] = v.to_i }
13
+ op.on("-p", "--port PORT") { |v| options[:port] = v.to_i }
13
14
  op.parse!
14
15
  end
15
16
 
16
- port = args[:port] || 23053
17
- gate = TCPServer.open(port)
18
-
19
- puts "Start listening GNTP on #{port}."
20
-
21
- begin
22
- loop do
23
- sock = gate.accept
24
- while msg = sock.gets
25
- sock.write <<EOS
26
- GNTP/1.0 -OK NONE\r\n
27
- \r\n
28
- EOS
29
- end
30
- end
31
- ensure
32
- gate.close
33
- sock.close if defined?(sock)
34
- puts "Closed."
35
- end
17
+ OkGntpd.start(options)
@@ -1,3 +1,3 @@
1
- module OkGntpd
2
- VERSION = "0.0.3"
1
+ class OkGntpd
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/ok_gntpd.rb CHANGED
@@ -1,5 +1,46 @@
1
- require "ok_gntpd/version"
1
+ require "socket"
2
2
 
3
- module OkGntpd
4
- # Your code goes here...
3
+ require File.expand_path("../ok_gntpd/version", __FILE__)
4
+
5
+ class OkGntpd
6
+ def self.start(options = nil)
7
+ new(options).start
8
+ end
9
+
10
+ attr_reader :options, :status
11
+
12
+ def initialize(options = nil)
13
+ @options = default_options.merge(options || {})
14
+ @status = :stop
15
+ end
16
+
17
+ def start
18
+ port = @options[:port]
19
+ puts "Start listening GNTP on #{port}."
20
+
21
+ gate = TCPServer.open(port)
22
+ begin
23
+ @status = :start
24
+ loop do
25
+ sock = gate.accept
26
+ sock.write <<EOS
27
+ GNTP/1.0 -OK NONE\r
28
+ \r
29
+ EOS
30
+ sock.close
31
+ end
32
+ ensure
33
+ gate.close
34
+ @status = :stop
35
+ puts "Closed."
36
+ end
37
+ end
38
+
39
+
40
+ private
41
+ def default_options
42
+ {
43
+ :port => 23053
44
+ }
45
+ end
5
46
  end
data/ok_gntpd.gemspec CHANGED
@@ -16,4 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "rspec"
19
22
  end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe OkGntpd do
4
+ specify do
5
+ server = OkGntpd.new(
6
+ :port => TCPServer.open('127.0.0.1', 0) { |s| s.addr[1] }
7
+ )
8
+ t = Thread.new(server) do |s|
9
+ Thread.pass
10
+ s.start
11
+ end
12
+ t.join(0.05) until server.status != :stop
13
+
14
+ begin
15
+ sock = TCPSocket.open("127.0.0.1", server.options[:port])
16
+ sock.write <<EOS
17
+ GNTP/1.0 REGISTER NONE\r
18
+ Application-Name: ok_gntpd\r
19
+ \r
20
+ EOS
21
+
22
+ response = sock.read
23
+ response.should == <<EOS
24
+ GNTP/1.0 -OK NONE\r
25
+ \r
26
+ EOS
27
+ ensure
28
+ sock.close
29
+ t.exit
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ $:.unshift File.expand_path("../../lib", __FILE__)
2
+
3
+ require "rubygems"
4
+ require "ok_gntpd"
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ config.order = 'random'
11
+ end
metadata CHANGED
@@ -1,16 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ok_gntpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Masato Ikeda
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-25 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
14
41
  description: An GNTPd which always return "OK".
15
42
  email:
16
43
  - masato.ikeda@gmail.com
@@ -20,6 +47,7 @@ extensions: []
20
47
  extra_rdoc_files: []
21
48
  files:
22
49
  - .gitignore
50
+ - .rspec
23
51
  - Gemfile
24
52
  - LICENSE.txt
25
53
  - README.md
@@ -28,28 +56,31 @@ files:
28
56
  - lib/ok_gntpd.rb
29
57
  - lib/ok_gntpd/version.rb
30
58
  - ok_gntpd.gemspec
59
+ - spec/ok_gntpd_spec.rb
60
+ - spec/spec_helper.rb
31
61
  homepage: https://github.com/a2ikm/ok_gntpd
32
62
  licenses: []
63
+ metadata: {}
33
64
  post_install_message:
34
65
  rdoc_options: []
35
66
  require_paths:
36
67
  - lib
37
68
  required_ruby_version: !ruby/object:Gem::Requirement
38
- none: false
39
69
  requirements:
40
- - - ! '>='
70
+ - - '>='
41
71
  - !ruby/object:Gem::Version
42
72
  version: '0'
43
73
  required_rubygems_version: !ruby/object:Gem::Requirement
44
- none: false
45
74
  requirements:
46
- - - ! '>='
75
+ - - '>='
47
76
  - !ruby/object:Gem::Version
48
77
  version: '0'
49
78
  requirements: []
50
79
  rubyforge_project:
51
- rubygems_version: 1.8.23
80
+ rubygems_version: 2.0.0.rc.2
52
81
  signing_key:
53
- specification_version: 3
82
+ specification_version: 4
54
83
  summary: An GNTPd which always return "OK".
55
- test_files: []
84
+ test_files:
85
+ - spec/ok_gntpd_spec.rb
86
+ - spec/spec_helper.rb