hole 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +1 -0
- data/bin/hole +11 -0
- data/hole.gemspec +23 -0
- data/lib/hole.rb +7 -0
- data/lib/hole/version.rb +3 -0
- data/lib/system/client/client.rb +5 -0
- data/lib/system/run/base.rb +63 -0
- data/lib/system/run/client.rb +14 -0
- data/lib/system/run/commands/server.rb +17 -0
- data/lib/system/run/run.rb +67 -0
- data/lib/system/server/server.rb +46 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9861eb0d1b6cf0de3f8c8f35df811d5f3d5cf5d5
|
4
|
+
data.tar.gz: 43dd120ff62858191651c05db387969a803f7d4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a5eb58d6276cecd8cde3ea70d1f03be03cd665815fb83443fa8d2c573223049fd87b8ac9ebcc72e674c7e22bc956fdfcb9ac00a209b6b6ef2eb25fd2ac2473b
|
7
|
+
data.tar.gz: c99b80a463c17f98c754358142d381c125a681ddb788a1b022d49be54145b8abaaaca2388de1b9f9a6222eb38b84ba0479daaf41a1960b000978b922796a5120
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sedat ÇİFTÇİ
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hole
ADDED
data/hole.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hole/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hole"
|
8
|
+
spec.version = Hole::VERSION
|
9
|
+
spec.authors = ["Sedat ÇİFTÇİ"]
|
10
|
+
spec.email = ["iamcodegrab@gmail.com"]
|
11
|
+
spec.summary = %q{CHANGE ME}
|
12
|
+
spec.description = %q{CHANGE ME}
|
13
|
+
spec.homepage = "https://github.com/sedatciftci/Hole"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/hole.rb
ADDED
data/lib/hole/version.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
class Hole::Run::Base
|
2
|
+
attr_writer :options, :config
|
3
|
+
|
4
|
+
|
5
|
+
def self.method_added(method)
|
6
|
+
return if self == Hole::Run::Base
|
7
|
+
return if private_method_defined? method
|
8
|
+
return if protected_method_defined? method
|
9
|
+
|
10
|
+
prefix = self.get_object_name
|
11
|
+
method_name = method.to_s == 'run' ? nil : method.to_s.gsub('_','-')
|
12
|
+
name = [prefix, method_name].compact
|
13
|
+
|
14
|
+
Hole::Run.add({
|
15
|
+
:name => name,
|
16
|
+
:class => self,
|
17
|
+
:method => method,
|
18
|
+
:options => options
|
19
|
+
})
|
20
|
+
@options = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_object_name(value=nil)
|
24
|
+
@object_name ||= begin
|
25
|
+
value ||= if self.name && !self.name.empty?
|
26
|
+
self.name.split('::').last
|
27
|
+
end
|
28
|
+
value.to_s.split(/(?=[A-Z])/).join('-').downcase if value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.syntax(value)
|
33
|
+
options[:syntax] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.description(value)
|
37
|
+
options[:description] = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.summary(value)
|
41
|
+
options[:summary] = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.example(value)
|
45
|
+
options[:example] = value
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.option(switches, description=nil, options={})
|
49
|
+
meta << {
|
50
|
+
:switches => switches,
|
51
|
+
:description => description,
|
52
|
+
:type => String
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.options
|
57
|
+
@options ||= {}
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.meta
|
61
|
+
options[:meta] ||=[]
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Hole::Run
|
2
|
+
class Server < Base
|
3
|
+
|
4
|
+
description "Start Hole Server"
|
5
|
+
syntax "$ hole server [IP] [PORT]"
|
6
|
+
|
7
|
+
def run(*args)
|
8
|
+
ip = args[0]
|
9
|
+
port = args[1]
|
10
|
+
|
11
|
+
puts "Hole server is started".light_blue
|
12
|
+
Hole::Server.new(ip ? ip : 'localhost', port ? port : 3000)
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'commander'
|
2
|
+
require 'commander/command'
|
3
|
+
require 'commander/import'
|
4
|
+
module Hole
|
5
|
+
module Run
|
6
|
+
autoload :Base, "system/run/base"
|
7
|
+
|
8
|
+
attr_accessor :main
|
9
|
+
|
10
|
+
def self.load_commands
|
11
|
+
Dir[File.join(File.dirname(__FILE__), "commands", "*.rb")].each do |file|
|
12
|
+
require file
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.add(opts)
|
18
|
+
commands[opts[:name]] = opts
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse_command(ins = Commander::Runner::instance)
|
22
|
+
|
23
|
+
commands.each_pair do |name, opts|
|
24
|
+
name = Array(name)
|
25
|
+
names = [name.reverse.join('-'), name.join(' ')] if name.length > 1
|
26
|
+
name = name.join(" ")
|
27
|
+
|
28
|
+
|
29
|
+
ins.command name do |c|
|
30
|
+
c.description = opts[:options][:description]
|
31
|
+
c.summary = opts[:options][:summary]
|
32
|
+
c.syntax = opts[:options][:syntax]
|
33
|
+
|
34
|
+
(options_metadata = Array(opts[:options][:meta])).each do |o|
|
35
|
+
option_data = [o[:switches], o[:type], o[:description]].compact.flatten(1)
|
36
|
+
c.option *option_data
|
37
|
+
o[:arg] = Commander::Runner.switch_to_sym(Array(o[:switches]).last)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
c.when_called do |args, options|
|
44
|
+
object = opts[:class].new
|
45
|
+
object.options = options
|
46
|
+
|
47
|
+
|
48
|
+
run(object,opts[:method],args)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
def self.run(obj, method, args)
|
58
|
+
obj.send(method, *args)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def self.commands
|
63
|
+
@commands ||= {}
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Hole
|
2
|
+
class Server
|
3
|
+
def initialize(ip, port)
|
4
|
+
@server = TCPServer.open(ip, port)
|
5
|
+
@connections = {}
|
6
|
+
@rooms = {}
|
7
|
+
@clients = {}
|
8
|
+
initialize_connections
|
9
|
+
run
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize_connections
|
13
|
+
@connections[:server] = @server
|
14
|
+
@connections[:rooms] = @rooms
|
15
|
+
@connections[:clients] = @clients
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
loop do
|
20
|
+
Thread.start(@server.accept) do |client|
|
21
|
+
username = client.gets.chomp.to_sym
|
22
|
+
|
23
|
+
@connections[:clients].each do |other_name, other_client|
|
24
|
+
if username == other_name || client == other_client
|
25
|
+
client.puts 'Sorry, but this name already exist'.red
|
26
|
+
Thread.kill self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
puts "#{username} #{client}"
|
30
|
+
@connections[:clients][username] = client
|
31
|
+
client.puts 'Connection established. Thank you for joining! Happy chatting.'.light_blue
|
32
|
+
listen_user_messages(username, client)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def listen_user_messages(username, client)
|
38
|
+
loop do
|
39
|
+
msg = client.gets.chomp
|
40
|
+
@connections[:clients].each do |other_name, other_client|
|
41
|
+
other_client.puts "#{username.to_s}: #{msg}".green.on_black unless other_name == username
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hole
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sedat ÇİFTÇİ
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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'
|
41
|
+
description: CHANGE ME
|
42
|
+
email:
|
43
|
+
- iamcodegrab@gmail.com
|
44
|
+
executables:
|
45
|
+
- hole
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/hole
|
55
|
+
- hole.gemspec
|
56
|
+
- lib/hole.rb
|
57
|
+
- lib/hole/version.rb
|
58
|
+
- lib/system/client/client.rb
|
59
|
+
- lib/system/run/base.rb
|
60
|
+
- lib/system/run/client.rb
|
61
|
+
- lib/system/run/commands/server.rb
|
62
|
+
- lib/system/run/run.rb
|
63
|
+
- lib/system/server/server.rb
|
64
|
+
homepage: https://github.com/sedatciftci/Hole
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.2.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: CHANGE ME
|
88
|
+
test_files: []
|