tamashii 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2975301e1fa682a9eec4fa18f6c4d77499ef89a7
4
- data.tar.gz: e794adc70265dedfef2d34a2ae4e703a0b86ed11
3
+ metadata.gz: 8ed79e176bb8b330675dcc17af8432771df1701b
4
+ data.tar.gz: 111bcf61a0685a6dba7c31146bf0ceb6a5582d6b
5
5
  SHA512:
6
- metadata.gz: e3b4b1f51372ac5c4b91aa150c4cda7bcbddb5a596f6f2e232fae978e96731cac7273d8d7e00dc4bfced9f258af41972609f255ee6ba70e46641c4bbb18d19e1
7
- data.tar.gz: 617a103df0234f6b9d8321b517e06efc4f7d10f4604c5a2c56a0d64c561054d7f780c4a35e2d7cf35b31026bea2f9c5fc0b95420a089526727246ab7409d55f6
6
+ metadata.gz: 54c52fe0e4afaea67fc83c1cf6a9105457f6126f3a3ceaeabf730d1e50fb4a91a399afbeb8969658e994a067239bdc562b4539bdb4e7a7b43c45c1c8cc2cb9f9
7
+ data.tar.gz: 0b76ec9201d43b852afeca20faf1ae02651f774d2c481de52849cc95118c8d311e4a5908a9433ccb36005684886148832b8513c078b6c12851e96a4b87d0912f
@@ -3,3 +3,9 @@ cache: bundler
3
3
  language: ruby
4
4
  rvm:
5
5
  - 2.4.1
6
+ before_script:
7
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
8
+ - chmod +x ./cc-test-reporter
9
+ - ./cc-test-reporter before-build
10
+ after_script:
11
+ - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
data/README.md CHANGED
@@ -1,38 +1,110 @@
1
- Tamashii [![Gem Version](https://badge.fury.io/rb/tamashii.svg)](https://badge.fury.io/rb/tamashii) [![Build Status](https://travis-ci.org/5xRuby/tamashii.svg?branch=master)](https://travis-ci.org/5xRuby/tamashii) [![Test Coverage](https://codeclimate.com/github/5xRuby/tamashii/badges/coverage.svg)](https://codeclimate.com/github/5xRuby/tamashii/coverage) [![Code Climate](https://codeclimate.com/github/5xRuby/tamashii/badges/gpa.svg)](https://codeclimate.com/github/5xRuby/tamashii)
1
+ Tamashii [![Gem Version](https://badge.fury.io/rb/tamashii.svg)](https://badge.fury.io/rb/tamashii) [![Build Status](https://travis-ci.org/tamashii-io/tamashii.svg?branch=master)](https://travis-ci.org/tamashii-io/tamashii) [![Test Coverage](https://codeclimate.com/github/tamashii-io/tamashii/badges/coverage.svg)](https://codeclimate.com/github/tamashii-io/tamashii/coverage) [![Code Climate](https://codeclimate.com/github/tamashii-io/tamashii/badges/gpa.svg)](https://codeclimate.com/github/tamashii-io/tamashii)
2
2
  ===
3
3
 
4
+ Tamashii is a package designed for IoT. You can write the WebSocket server and client easily by using this gem.
4
5
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tamashii`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- TODO: Delete this and the text above, and describe your gem
8
6
 
9
7
  ## Installation
10
8
 
11
- Add this line to your application's Gemfile:
9
+ Add the following code to your `Gemfile`
12
10
 
13
11
  ```ruby
14
12
  gem 'tamashii'
15
13
  ```
16
14
 
17
15
  And then execute:
16
+ ```ruby
17
+ $ bundle install
18
+ ```
19
+
20
+ Or install it yourself with:
21
+ ```ruby
22
+ $ gem install tamashii
23
+ ```
18
24
 
19
- $ bundle
25
+ ## Usage
20
26
 
21
- Or install it yourself as:
27
+ There are two section in Tamashii, Server and Client, is responsible for the WebSocket server and client, respectively.
22
28
 
23
- $ gem install tamashii
29
+ ### Server
24
30
 
25
- ## Usage
31
+ Server section is a server designed based on Rack, it can not only be easily compatible with the web server, such as Puma, Passenger, but also be used as a module in the Rails and other projects.
32
+
33
+ To start the server, generate `config.ru` and add the following code to it.
34
+
35
+ ```ruby
36
+ require 'tamashii/server'
37
+
38
+ run Tamashii::Server::Base.new
39
+ ```
40
+
41
+ Then, you can start the server with:
42
+
43
+ $ rackup
44
+ If you want to start the server with other web server, such as Puma:
45
+
46
+ $ puma
47
+
48
+ > You can refer to the project in [tamashii-manager](https://github.com/5xRuby/tamashii-manager) in the IoT server application.
49
+
50
+ #### Connection
51
+
52
+ In Tamashii, we only need to focus on how to connect with WebSocket users to exchange information, on the process of multi-process web server problems have been resolved in Tamashii.
53
+
54
+ We can create a `Client` object to handle the behavior of each user.
55
+
56
+ ```ruby
57
+ Tamashii::Server.config do |config|
58
+ config.connection_class = Client
59
+ end
60
+ ```
61
+
62
+ In `Client` , there are four events that need to be handled.
63
+
64
+ * `on_open` : when the user is connected to the server
65
+ * `on_message` : when the server receives the message from user
66
+ * `on_error` : when the server gets an error
67
+ * `on_close` : when the connection is shut down
68
+
69
+ In most cases, we only need to deal with parts of `on_message` , the other events can be handled as needed.
70
+
71
+ ```ruby
72
+ class Client
73
+ def on_message(data)
74
+ # Processing for the received Data (Binary)
75
+ end
76
+ end
77
+ ```
78
+
79
+ By default Tamashii will broadcast the received message to other clients automatically.
80
+
81
+
82
+ ### Client
83
+
84
+ The client is in another repository: [tamashii-client](https://github.com/tamashii-io/tamashii-client)
26
85
 
27
- TODO: Write usage instructions here
28
86
 
29
87
  ## Development
30
88
 
31
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
89
+ To get the source code
90
+
91
+ $ git clone git@github.com:tamashii-io/tamashii.git
92
+
93
+ Initialize the development environment
94
+
95
+ $ ./bin/setup
96
+
97
+ Run the spec
98
+
99
+ $ rspec
100
+
101
+ Installation the version of development on localhost
102
+
103
+ $ bundle exec rake install
32
104
 
33
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
105
+ ## Contribution
34
106
 
35
- ## Contributing
107
+ Please report to us on [GitHub](https://github.com/tamashii-io/tamashii) if there is any bug or suggested modified.
36
108
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tamashii.
109
+ The project was developed by [5xruby Inc.](https://5xruby.tw/)
38
110
 
@@ -6,10 +6,11 @@ require 'logger/colors'
6
6
  require 'websocket/driver'
7
7
  require 'rack'
8
8
  require 'nio'
9
- require 'thread'
10
9
  require 'concurrent'
11
10
  require 'redis'
12
11
 
12
+ require 'tamashii/hookable'
13
+
13
14
  module Tamashii
14
15
  # :nodoc:
15
16
  module Server
@@ -33,3 +34,7 @@ module Tamashii
33
34
  end
34
35
  end
35
36
  end
37
+
38
+ Tamashii::Hook.after(:config) do |config|
39
+ config.register(:server, Tamashii::Server.config)
40
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tamashii/configurable'
3
+ require 'tamashii/config'
4
4
 
5
5
  module Tamashii
6
6
  module Server
@@ -8,9 +8,9 @@ module Tamashii
8
8
  class Config
9
9
  include Tamashii::Configurable
10
10
 
11
- register :connection_class, Connection::Base
12
- register :pubsub_class, Subscription::Redis
13
- register :log_path, STDOUT
11
+ config :connection_class, default: Connection::Base
12
+ config :pubsub_class, default: Subscription::Redis
13
+ config :log_path, default: STDOUT
14
14
  end
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tamashii
4
- VERSION = "0.3.6"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  lib = File.expand_path('../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -31,19 +31,20 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ['lib']
32
32
 
33
33
  spec.add_runtime_dependency "concurrent-ruby"
34
+ spec.add_runtime_dependency "logger-colors"
35
+ spec.add_runtime_dependency "nio4r"
34
36
  spec.add_runtime_dependency "rack"
37
+ spec.add_runtime_dependency "redis"
35
38
  spec.add_runtime_dependency "tamashii-common"
39
+ spec.add_runtime_dependency "tamashii-config"
40
+ spec.add_runtime_dependency "tamashii-hookable"
36
41
  spec.add_runtime_dependency "websocket-driver"
37
- spec.add_runtime_dependency "nio4r"
38
- spec.add_runtime_dependency "redis"
39
- spec.add_runtime_dependency "logger-colors"
40
42
 
41
43
  spec.add_development_dependency 'bundler', '~> 1.14'
44
+ spec.add_development_dependency "codeclimate-test-reporter"
45
+ spec.add_development_dependency "guard-rspec"
46
+ spec.add_development_dependency "rack-test"
42
47
  spec.add_development_dependency 'rake', '~> 10.0'
43
48
  spec.add_development_dependency 'rspec', '~> 3.0'
44
- spec.add_development_dependency "rack-test"
45
49
  spec.add_development_dependency "simplecov"
46
- spec.add_development_dependency "guard"
47
- spec.add_development_dependency "guard-rspec"
48
- spec.add_development_dependency "codeclimate-test-reporter"
49
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tamashii
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-06-06 00:00:00.000000000 Z
13
+ date: 2017-11-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -27,7 +27,7 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
- name: rack
30
+ name: logger-colors
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
@@ -41,7 +41,7 @@ dependencies:
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
- name: tamashii-common
44
+ name: nio4r
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
@@ -55,7 +55,7 @@ dependencies:
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
- name: websocket-driver
58
+ name: rack
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
@@ -69,7 +69,7 @@ dependencies:
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
- name: nio4r
72
+ name: redis
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="
@@ -83,7 +83,7 @@ dependencies:
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
- name: redis
86
+ name: tamashii-common
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
@@ -97,7 +97,7 @@ dependencies:
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  - !ruby/object:Gem::Dependency
100
- name: logger-colors
100
+ name: tamashii-config
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - ">="
@@ -111,49 +111,49 @@ dependencies:
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  - !ruby/object:Gem::Dependency
114
- name: bundler
114
+ name: tamashii-hookable
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - "~>"
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: '1.14'
120
- type: :development
119
+ version: '0'
120
+ type: :runtime
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - "~>"
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
- version: '1.14'
126
+ version: '0'
127
127
  - !ruby/object:Gem::Dependency
128
- name: rake
128
+ name: websocket-driver
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - "~>"
131
+ - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: '10.0'
134
- type: :development
133
+ version: '0'
134
+ type: :runtime
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - "~>"
138
+ - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: '10.0'
140
+ version: '0'
141
141
  - !ruby/object:Gem::Dependency
142
- name: rspec
142
+ name: bundler
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - "~>"
146
146
  - !ruby/object:Gem::Version
147
- version: '3.0'
147
+ version: '1.14'
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - "~>"
153
153
  - !ruby/object:Gem::Version
154
- version: '3.0'
154
+ version: '1.14'
155
155
  - !ruby/object:Gem::Dependency
156
- name: rack-test
156
+ name: codeclimate-test-reporter
157
157
  requirement: !ruby/object:Gem::Requirement
158
158
  requirements:
159
159
  - - ">="
@@ -167,7 +167,7 @@ dependencies:
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  - !ruby/object:Gem::Dependency
170
- name: simplecov
170
+ name: guard-rspec
171
171
  requirement: !ruby/object:Gem::Requirement
172
172
  requirements:
173
173
  - - ">="
@@ -181,7 +181,7 @@ dependencies:
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  - !ruby/object:Gem::Dependency
184
- name: guard
184
+ name: rack-test
185
185
  requirement: !ruby/object:Gem::Requirement
186
186
  requirements:
187
187
  - - ">="
@@ -195,21 +195,35 @@ dependencies:
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  - !ruby/object:Gem::Dependency
198
- name: guard-rspec
198
+ name: rake
199
199
  requirement: !ruby/object:Gem::Requirement
200
200
  requirements:
201
- - - ">="
201
+ - - "~>"
202
202
  - !ruby/object:Gem::Version
203
- version: '0'
203
+ version: '10.0'
204
204
  type: :development
205
205
  prerelease: false
206
206
  version_requirements: !ruby/object:Gem::Requirement
207
207
  requirements:
208
- - - ">="
208
+ - - "~>"
209
209
  - !ruby/object:Gem::Version
210
- version: '0'
210
+ version: '10.0'
211
211
  - !ruby/object:Gem::Dependency
212
- name: codeclimate-test-reporter
212
+ name: rspec
213
+ requirement: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - "~>"
216
+ - !ruby/object:Gem::Version
217
+ version: '3.0'
218
+ type: :development
219
+ prerelease: false
220
+ version_requirements: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - "~>"
223
+ - !ruby/object:Gem::Version
224
+ version: '3.0'
225
+ - !ruby/object:Gem::Dependency
226
+ name: simplecov
213
227
  requirement: !ruby/object:Gem::Requirement
214
228
  requirements:
215
229
  - - ">="
@@ -244,7 +258,6 @@ files:
244
258
  - bin/console
245
259
  - bin/setup
246
260
  - lib/tamashii.rb
247
- - lib/tamashii/configurable.rb
248
261
  - lib/tamashii/server.rb
249
262
  - lib/tamashii/server/base.rb
250
263
  - lib/tamashii/server/client.rb
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tamashii
4
- # :nodoc:
5
- module Configurable
6
- # :nodoc:
7
- module ClassMethods
8
- def register(key, default, &_block)
9
- @defaults ||= {}
10
- return @defaults[key.to_sym] = yield if block_given?
11
- @defaults[key.to_sym] = default
12
- end
13
-
14
- def exist?(key)
15
- @defaults.key?(key.to_sym) || @defaults.key?(key.to_s[0..-2].to_sym)
16
- end
17
-
18
- def default_value(key)
19
- @defaults[key.to_sym]
20
- end
21
- end
22
-
23
- def self.included(klass)
24
- klass.extend ClassMethods
25
- end
26
-
27
- def config(key, value = nil, &_block)
28
- @configs ||= {}
29
- return unless self.class.exist?(key)
30
- return @configs[key.to_sym] || self.class.default_value(key) if value.nil?
31
- return @configs[key.to_sym] = yield if block_given?
32
- @configs[key.to_sym] = value
33
- end
34
-
35
- def respond_to_missing?(name, _all = false)
36
- self.class.exist?(name)
37
- end
38
-
39
- def method_missing(name, *args, &block)
40
- return super unless self.class.exist?(name)
41
- return config(name.to_sym, nil, &block) unless name.to_s.end_with?('=')
42
- config(name.to_s[0..-2].to_sym, args.first)
43
- end
44
- end
45
- end