pomelo-citrus-loader 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +20 -0
- data/Rakefile +0 -0
- data/citrus-loader.gemspec +24 -0
- data/lib/citrus-loader.rb +7 -0
- data/lib/citrus-loader/loader.rb +144 -0
- data/lib/citrus-loader/version.rb +7 -0
- data/spec/spec_helper.rb +14 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d499a4b3450dcfbd5178fd31ce310d24c41b0a46
|
4
|
+
data.tar.gz: f7336be49b0b0f82bfeaeed4666adb293be442e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a846a1a6dbe5397ca903370948f7761ec7a56c36b87a7f94b6de8f15f57d4bd4c5a7156a6a39b2fd4fb4f7c88a06bf13918e5e87ffe326be4c53395974987791
|
7
|
+
data.tar.gz: 7820dd80b94944dd3a6ba712852db7fdfd8ad6513c1c4f72f05b996aaa7190141782033afd7ee030456eff9207e66270f057a711b51617c566b97992ffd3e74e
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
## Welcome to pomelo-citrus-loader
|
2
|
+
|
3
|
+
pomelo-citrus-loader is a simple clone of pomelo-loader written in Ruby using EventMachine.
|
4
|
+
|
5
|
+
## Motivation
|
6
|
+
|
7
|
+
Since NodeJS is influenced by Ruby EventMachine and Python's Twisted model, Ruby should also be able to have its own game server framework like pomelo.
|
8
|
+
|
9
|
+
Ruby is a very expressive and eloquent programming language. I was an RoR programmer before and I really like Ruby, When developing this project, I have used many skills like meta-programming and they give me the real pleasures.
|
10
|
+
|
11
|
+
Recently, I would focus on my daily work, so I open source this project and hope to have more people participate in this project.
|
12
|
+
|
13
|
+
## Todo
|
14
|
+
|
15
|
+
This gem is the very first gem I have done in my whole work, it needs to be improved but it already has the ablity to provide the basic infrastructure to other gems, other gems exist in my own repository.
|
16
|
+
|
17
|
+
## Links
|
18
|
+
|
19
|
+
* [EventMachine](https://github.com/eventmachine/eventmachine)
|
20
|
+
* [pomelo-loader](https://github.com/NetEase/pomelo-loader)
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 16 July 2014
|
4
|
+
|
5
|
+
$:.push File.expand_path('../lib', __FILE__)
|
6
|
+
|
7
|
+
require 'citrus-loader/version'
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = 'pomelo-citrus-loader'
|
11
|
+
spec.version = CitrusLoader::VERSION
|
12
|
+
spec.platform = Gem::Platform::RUBY
|
13
|
+
spec.authors = ['MinixLi']
|
14
|
+
spec.email = 'MinixLi1986@gmail.com'
|
15
|
+
spec.description = %q{pomelo-citrus-loader is a simple clone of pomelo-loader}
|
16
|
+
spec.summary = %q{pomelo-loader clone written in Ruby using EventMachine}
|
17
|
+
spec.homepage = 'https://github.com/minixli/pomelo-citrus-loader'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split($/)
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 17 July 2014
|
4
|
+
|
5
|
+
module CitrusLoader
|
6
|
+
|
7
|
+
module ::Citrus end
|
8
|
+
|
9
|
+
# AppRemote
|
10
|
+
::Citrus::AppRemote = Class.new {
|
11
|
+
def initialize context
|
12
|
+
@app = context
|
13
|
+
end
|
14
|
+
}
|
15
|
+
# AppHandler
|
16
|
+
::Citrus::AppHandler = Class.new {
|
17
|
+
def initialize context
|
18
|
+
@app = context
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
# HandlerFilter
|
23
|
+
::Citrus::HandlerFilter = Class.new
|
24
|
+
# RpcFilter
|
25
|
+
::Citrus::RpcFilter = Class.new
|
26
|
+
|
27
|
+
@app_handler_loaded = {}
|
28
|
+
@app_remote_loaded = {}
|
29
|
+
|
30
|
+
@handler_filters_loaded = {}
|
31
|
+
@rpc_filters_loaded = {}
|
32
|
+
|
33
|
+
class << self
|
34
|
+
attr_reader :app_handler_loaded, :app_remote_loaded
|
35
|
+
attr_reader :handler_filters_loaded, :rpc_filters_loaded
|
36
|
+
end
|
37
|
+
|
38
|
+
# Load app handler
|
39
|
+
#
|
40
|
+
# @param [String] path
|
41
|
+
def load_app_handler path
|
42
|
+
if !File.directory? path
|
43
|
+
raise ArgumentError, 'expected a directory'
|
44
|
+
end
|
45
|
+
|
46
|
+
result = []
|
47
|
+
Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
|
48
|
+
if CitrusLoader.app_handler_loaded[filepath]
|
49
|
+
result << CitrusLoader.app_handler_loaded[filepath]
|
50
|
+
else
|
51
|
+
::Citrus::AppHandler.define_singleton_method(:inherited) { |subclass|
|
52
|
+
CitrusLoader.app_handler_loaded[filepath] = subclass
|
53
|
+
result << subclass
|
54
|
+
}
|
55
|
+
require filepath
|
56
|
+
end
|
57
|
+
}
|
58
|
+
result
|
59
|
+
end
|
60
|
+
|
61
|
+
# Load app remote
|
62
|
+
#
|
63
|
+
# @param [String] path
|
64
|
+
def load_app_remote path
|
65
|
+
if !File.directory? path
|
66
|
+
raise ArgumentError, 'expected a directory'
|
67
|
+
end
|
68
|
+
|
69
|
+
subclasses = []
|
70
|
+
Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
|
71
|
+
if subclass = CitrusLoader.app_remote_loaded[filepath]
|
72
|
+
subclasses << subclass
|
73
|
+
else
|
74
|
+
::Citrus::AppRemote.define_singleton_method(:inherited) { |subclass|
|
75
|
+
CitrusLoader.app_remote_loaded[filepath] = subclass
|
76
|
+
subclasses << subclass
|
77
|
+
}
|
78
|
+
require filepath
|
79
|
+
end
|
80
|
+
}
|
81
|
+
|
82
|
+
result = {}
|
83
|
+
subclasses.each { |subclass|
|
84
|
+
service = get_service_name subclass
|
85
|
+
result[service] = subclass
|
86
|
+
}
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
# Load handler filters
|
91
|
+
#
|
92
|
+
# @param [String] path
|
93
|
+
def load_handler_filters path
|
94
|
+
if !File.directory? path
|
95
|
+
raise ArgumentError, 'expected a directory'
|
96
|
+
end
|
97
|
+
|
98
|
+
result = []
|
99
|
+
Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
|
100
|
+
if CitrusLoader.handler_filters_loaded[filepath]
|
101
|
+
result << CitrusLoader.handler_filters_loaded[filepath]
|
102
|
+
else
|
103
|
+
::Citrus::HandlerFilter.define_singleton_method(:inherited) { |subclass|
|
104
|
+
CitrusLoader.handler_filters_loaded[filepath] = subclass
|
105
|
+
result << subclass
|
106
|
+
}
|
107
|
+
require filepath
|
108
|
+
end
|
109
|
+
}
|
110
|
+
result
|
111
|
+
end
|
112
|
+
|
113
|
+
# Load rpc filters
|
114
|
+
#
|
115
|
+
# @param [String] path
|
116
|
+
def load_rpc_filters path
|
117
|
+
if !File.directory? path
|
118
|
+
raise ArgumentError, 'expected a directory'
|
119
|
+
end
|
120
|
+
|
121
|
+
result = []
|
122
|
+
Dir.glob(File.join(path, '') + '*.rb').each { |filepath|
|
123
|
+
if CitrusLoader.rpc_filters_loaded[filepath]
|
124
|
+
result << CitrusLoader.rpc_filters_loaded[filepath]
|
125
|
+
else
|
126
|
+
::Citrus::RpcFilter.define_singleton_method(:inherited) { |subclass|
|
127
|
+
CitrusLoader.rpc_filters_loaded[filepath] = subclass
|
128
|
+
result << subclass
|
129
|
+
}
|
130
|
+
require filepath
|
131
|
+
end
|
132
|
+
}
|
133
|
+
result
|
134
|
+
end
|
135
|
+
|
136
|
+
# Get service name
|
137
|
+
#
|
138
|
+
# @param [Class] subclass
|
139
|
+
def get_service_name subclass
|
140
|
+
service = subclass.name
|
141
|
+
service[0] = service[0].downcase
|
142
|
+
service
|
143
|
+
end
|
144
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 16 July 2014
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/citrus-loader', __FILE__)
|
6
|
+
|
7
|
+
RSpec.configure { |config|
|
8
|
+
config.mock_with(:rspec) { |c|
|
9
|
+
c.syntax = [:should, :expect]
|
10
|
+
}
|
11
|
+
config.expect_with(:rspec) { |c|
|
12
|
+
c.syntax = [:should, :expect]
|
13
|
+
}
|
14
|
+
}
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pomelo-citrus-loader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MinixLi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: pomelo-citrus-loader is a simple clone of pomelo-loader
|
14
|
+
email: MinixLi1986@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- Rakefile
|
21
|
+
- citrus-loader.gemspec
|
22
|
+
- lib/citrus-loader.rb
|
23
|
+
- lib/citrus-loader/loader.rb
|
24
|
+
- lib/citrus-loader/version.rb
|
25
|
+
- spec/spec_helper.rb
|
26
|
+
homepage: https://github.com/minixli/pomelo-citrus-loader
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.4.1
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: pomelo-loader clone written in Ruby using EventMachine
|
50
|
+
test_files:
|
51
|
+
- spec/spec_helper.rb
|