reactomatic 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10fb81989a12a6d13e2c866a68f7d4834f452170
4
- data.tar.gz: 678098ae122e7fe1af799865bb4e6b1183c94a54
3
+ metadata.gz: 7dc658891bae991380cbd03d824d72ed76335831
4
+ data.tar.gz: f5851a9911d30e03e12945908196882760da161a
5
5
  SHA512:
6
- metadata.gz: aa2e188f6c81f71bd006ca24c318123ae3efa8bc5fb5dad81aa6ad04235a3361f6c1ffd36ca9b45a30dacdb172a1f60e830a7a08e77c5ab782be7bc9074c16b6
7
- data.tar.gz: 0f89453b08af8af5e0dae8793a3e9fc320d7fe710537121163c4d11bc7225541c104461487eb2ca0852f157686f091d255634698e9ca15f4242e72cd3df0747d
6
+ metadata.gz: a2745cb296f950fe5aefd844845b3f1840d046a7a76ecbd3e0eb044fb3001d0e71ce8ab7783c0ceb691f1183e908e64d85e48cc23e395c44c486a7d9da0f498c
7
+ data.tar.gz: 642286d6232918b5309b9a32b5e4a27275f2163e39ff476cf05004c90146308f8d37b5f6c634b6be3d13d5633d6655d2e55e2460be3b3b1d4f9df62875fc56cb
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in reactomatic.gemspec
3
+ gem 'coveralls', :require => false
4
+
4
5
  gemspec
5
6
 
6
7
  platforms :ruby do
data/README.md CHANGED
@@ -1,16 +1,13 @@
1
- # Reactomatic
1
+ # Reactomatic [![Build Status](https://travis-ci.org/chadrem/reactomatic.svg)](https://travis-ci.org/chadrem/reactomatic) [![Coverage Status](https://coveralls.io/repos/chadrem/reactomatic/badge.svg?branch=master&service=github)](https://coveralls.io/github/chadrem/reactomatic?branch=master)
2
2
 
3
- 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/reactomatic`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Reactomatic is an implementation of the [Reactor Pattern](https://en.wikipedia.org/wiki/Reactor_pattern) for Ruby.
4
+ It's built on top of the excellent [nio4r](https://github.com/celluloid/nio4r) gem.
6
5
 
7
6
  ## Installation
8
7
 
9
8
  Add this line to your application's Gemfile:
10
9
 
11
- ```ruby
12
- gem 'reactomatic'
13
- ```
10
+ gem 'reactomatic'
14
11
 
15
12
  And then execute:
16
13
 
@@ -20,19 +17,75 @@ Or install it yourself as:
20
17
 
21
18
  $ gem install reactomatic
22
19
 
23
- ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ ## Reactors
22
+
23
+ The ````Reactor```` class is the heart of Reactomatic.
24
+ Reactors handle all the low level details of running an event loop in a dedicated thread.
25
+ This means you get to focus on writing application logic instead of low level socket code.
26
+
27
+ Reactomatic creates a default reactor that should be sufficient for most applications (you can also create custom ones):
28
+
29
+ Reactomatic.reactor
30
+
31
+ *Instance methods:*
32
+
33
+ - ````stop````: Stop the reactor and its dedicated thread. This doesn't close any open connections or running servers.
34
+ - ````start````: Start the reactor and its dedicated thread.
35
+ - ````next_tick````: Run a block of code on the reactor's thread in the future (next time it loops).
36
+ - ````schedule````: Run a block of code on the reactor's thread immediately if called from the reactor thread. If called from a differet thread, the block will run in the future using ````next_tick````.
37
+
38
+ ## TCP Servers
39
+
40
+ The ````TcpServer```` class lets you easily listen for new connections and pass them off to a connection class.
41
+ Here is an example:
42
+
43
+ server = Reactomatic::TcpServer.new
44
+ server.listen('0.0.0.0', 9000, Reactomatic::TcpConnection)
45
+
46
+ The above code will listen for new connections on ````0.0.0.0:9000````.
47
+ When it receives one, it will create an instance of ````Reactomatic::TcpConnection```` to process data associated with the connection. Below you will learn how to create your own custom connection class to override the default behavior.
48
+
49
+ *Instance methods:*
50
+
51
+ - ````listen(host, port, klass)````: Listen for incoming connections.
52
+ - ````close````: Stop listening for incoming connections. Already established connections will remain open.
53
+
54
+ ## TCP Connections
55
+
56
+ The ````TcpConnection```` base class is how you interface your application logic with sending and receiving data.
57
+ It's designed so that your custom connection classes inherit from it and override event handlers.
58
+ Here's an example:
59
+
60
+ class MyConnection < Reactomatic::TcpConnection
61
+ private
62
+ def on_initialize
63
+ puts "MyConnection: initialized!"
64
+ end
65
+
66
+ def on_receive_data(data)
67
+ puts "MyConnection: received #{data.bytesize} bytes of data and echoing back!"
68
+ send_data(data)
69
+ end
70
+
71
+ def on_sent_data(num_bytes)
72
+ puts "MyConnection: sent #{num_bytes} of data!"
73
+ end
26
74
 
27
- ## Development
75
+ def on_disconnect
76
+ puts "MyConnection: disconnected!"
77
+ end
78
+ end
28
79
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
+ *Instance methods:*
30
81
 
31
- 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).
82
+ - ````reactor````: Returns a reference to this connections reactor.
83
+ - ````send_data(data)````: Queues data for sending. If it can't be sent immediately, the data will be buffered and sent in the future.
84
+ - ````close````: Immediately closes the connection.
32
85
 
33
86
  ## Contributing
34
87
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/reactomatic.
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chadrem/reactomatic.
36
89
 
37
90
 
38
91
  ## License
@@ -24,10 +24,13 @@ module Reactomatic
24
24
  end
25
25
 
26
26
  def connect(host, port)
27
+ raise 'Not implemented yet.'
27
28
  end
28
29
 
29
30
  def send_data(data)
30
31
  @lock.synchronize do
32
+ return nil if @socket.nil?
33
+
31
34
  @write_buffer.append(data)
32
35
  write_nonblock
33
36
  register
@@ -15,7 +15,7 @@ module Reactomatic
15
15
  @klass = klass
16
16
 
17
17
  @socket = TCPServer.new(@host, @port)
18
- @reactor.register(@socket, :r, method(:__selected__))
18
+ @reactor.register(@socket, :r, method(:selected))
19
19
 
20
20
  nil
21
21
  end
@@ -36,7 +36,7 @@ module Reactomatic
36
36
  # Internal methods (don't use).
37
37
  #
38
38
 
39
- def __selected__(monitor)
39
+ def selected(monitor)
40
40
  if monitor.closed?
41
41
  @reactor.deregister(@server)
42
42
  return
@@ -1,3 +1,3 @@
1
1
  module Reactomatic
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,80 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactomatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Remesch
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: nio4r
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ~>
17
+ - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.1'
19
- name: nio4r
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: bundler
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: '1.10'
33
- name: bundler
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.10'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rake
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - ~>
45
+ - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '10.0'
47
- name: rake
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: minitest
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - '>='
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: minitest
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description:
69
+ description:
70
70
  email:
71
71
  - chad@remesch.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
78
  - Gemfile
79
79
  - LICENSE.txt
80
80
  - README.md
@@ -93,24 +93,24 @@ homepage: https://github.com/chadrem/reactomatic
93
93
  licenses:
94
94
  - MIT
95
95
  metadata: {}
96
- post_install_message:
96
+ post_install_message:
97
97
  rdoc_options: []
98
98
  require_paths:
99
99
  - lib
100
100
  required_ruby_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.4.6
113
- signing_key:
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
114
  specification_version: 4
115
115
  summary: A network library based on the reactor pattern.
116
116
  test_files: []