chatbox 0.1.0
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 +14 -0
- data/.rspec +3 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/chatbox.gemspec +26 -0
- data/lib/chatbox.rb +43 -0
- data/lib/chatbox/configuration.rb +5 -0
- data/lib/chatbox/draft.rb +20 -0
- data/lib/chatbox/inbox.rb +30 -0
- data/lib/chatbox/memory_store.rb +21 -0
- data/lib/chatbox/outbox.rb +30 -0
- data/lib/chatbox/version.rb +3 -0
- data/spec/chatbox_spec.rb +64 -0
- data/spec/lib/draft_spec.rb +17 -0
- data/spec/spec_helper.rb +43 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d1dc4166223405dcc13dfee12cb0235cd95c7ae7
|
4
|
+
data.tar.gz: 62e0ca3a43df9cd1dcade47072105939cc9690d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 045a0f5b936cbff0e9bb1e68b6ec740457881a565091a4ff0003d4e2c8ca752c47482d6f276bccdc5f80f11239516b1b5b4fb4836ec4c1e0464ceac3a1d5e327
|
7
|
+
data.tar.gz: 71ad790f0d3332334d40bcdcfb2484afce682aa35c1a810ab566f8fa948f8aeec9ccc61d994281ae207315f1e44a0bceee7747f72c766d995df446ed13f96b94
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Austin Schneider
|
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
@@ -0,0 +1,31 @@
|
|
1
|
+
# Chatbox
|
2
|
+
|
3
|
+
Simple messaging system.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'chatbox'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install chatbox
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/chatbox/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/chatbox.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chatbox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'chatbox'
|
8
|
+
spec.version = Chatbox::VERSION
|
9
|
+
spec.authors = ['Austin Schneider']
|
10
|
+
spec.email = ['austinthecoder@gmail.com']
|
11
|
+
spec.summary = 'Simple messaging system.'
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = ''
|
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.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
|
25
|
+
spec.add_dependency 'activesupport', '>= 3'
|
26
|
+
end
|
data/lib/chatbox.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
require 'chatbox/configuration'
|
3
|
+
require 'chatbox/draft'
|
4
|
+
require 'chatbox/inbox'
|
5
|
+
require 'chatbox/memory_store'
|
6
|
+
require 'chatbox/outbox'
|
7
|
+
require 'chatbox/version'
|
8
|
+
|
9
|
+
module Chatbox
|
10
|
+
extend self
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield config
|
14
|
+
end
|
15
|
+
|
16
|
+
def reset_config!
|
17
|
+
@config = nil
|
18
|
+
@store = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def deliver_message!(args)
|
22
|
+
args.merge! store: store
|
23
|
+
Draft.new(args).deliver!
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch_inbox_for(entity)
|
27
|
+
Inbox.new entity: entity, store: store
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch_outbox_for(entity)
|
31
|
+
Outbox.new entity: entity, store: store
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def config
|
37
|
+
@config ||= Configuration.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def store
|
41
|
+
@store ||= config.store || MemoryStore.new
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Chatbox
|
2
|
+
class Draft
|
3
|
+
def initialize(from:, to:, body:, store:)
|
4
|
+
@from_id = from.chatbox_id
|
5
|
+
@to_id = to.chatbox_id
|
6
|
+
@body = body
|
7
|
+
@store = store
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :to_id, :from_id, :body
|
11
|
+
|
12
|
+
def deliver!
|
13
|
+
store.add_message self
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :store
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Chatbox
|
2
|
+
class Inbox
|
3
|
+
def initialize(entity:, store:)
|
4
|
+
@id = entity.chatbox_id
|
5
|
+
@store = store
|
6
|
+
end
|
7
|
+
|
8
|
+
delegate :size, :[], to: :messages
|
9
|
+
|
10
|
+
def ==(other)
|
11
|
+
other.is_a?(self.class) && id == other.id && store == other.store
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :eql?, :==
|
15
|
+
|
16
|
+
def hash
|
17
|
+
id.hash ^ store.hash
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
attr_reader :id, :store
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def messages
|
27
|
+
@messages ||= store.find_all_messages_by_to_id id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Chatbox
|
2
|
+
class MemoryStore
|
3
|
+
def add_message(message)
|
4
|
+
messages << message
|
5
|
+
end
|
6
|
+
|
7
|
+
def find_all_messages_by_to_id(to_id)
|
8
|
+
messages.select { |message| message.to_id == to_id }
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_all_messages_by_from_id(from_id)
|
12
|
+
messages.select { |message| message.from_id == from_id }
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def messages
|
18
|
+
@messages ||= []
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Chatbox
|
2
|
+
class Outbox
|
3
|
+
def initialize(entity:, store:)
|
4
|
+
@id = entity.chatbox_id
|
5
|
+
@store = store
|
6
|
+
end
|
7
|
+
|
8
|
+
delegate :size, :[], to: :messages
|
9
|
+
|
10
|
+
def ==(other)
|
11
|
+
other.is_a?(self.class) && id == other.id && store == other.store
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :eql?, :==
|
15
|
+
|
16
|
+
def hash
|
17
|
+
id.hash ^ store.hash
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
attr_reader :id, :store
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def messages
|
27
|
+
@messages ||= store.find_all_messages_by_from_id id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'chatbox'
|
2
|
+
|
3
|
+
describe Chatbox do
|
4
|
+
before { Chatbox.reset_config! }
|
5
|
+
|
6
|
+
context 'integration' do
|
7
|
+
it 'sending and receiving a message' do
|
8
|
+
austin = double 'entity', chatbox_id: 1
|
9
|
+
rachel = double 'entity', chatbox_id: 2
|
10
|
+
|
11
|
+
Chatbox.deliver_message! from: austin, to: rachel, body: 'Hello! How are you?'
|
12
|
+
|
13
|
+
rachels_inbox = Chatbox.fetch_inbox_for rachel
|
14
|
+
expect(rachels_inbox.size).to eq 1
|
15
|
+
message = rachels_inbox[0]
|
16
|
+
expect(message.from_id).to eq 1
|
17
|
+
expect(message.body).to eq 'Hello! How are you?'
|
18
|
+
|
19
|
+
austins_outbox = Chatbox.fetch_outbox_for austin
|
20
|
+
expect(austins_outbox.size).to eq 1
|
21
|
+
expect(message.to_id).to eq 2
|
22
|
+
expect(message.body).to eq 'Hello! How are you?'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.deliver_message!' do
|
27
|
+
before do
|
28
|
+
@from = double 'entity'
|
29
|
+
@to = double 'entity'
|
30
|
+
@draft = double 'draft', deliver!: nil
|
31
|
+
allow(Chatbox::Draft).to receive(:new).and_return @draft
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'instantiates a draft with the configured store' do
|
35
|
+
store = double 'store'
|
36
|
+
Chatbox.configure { |config| config.store = store }
|
37
|
+
expect(Chatbox::Draft).to receive(:new).with from: @from, to: @to, body: 'Hi', store: store
|
38
|
+
Chatbox.deliver_message! from: @from, to: @to, body: 'Hi'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'delivers the draft' do
|
42
|
+
expect(@draft).to receive :deliver!
|
43
|
+
Chatbox.deliver_message! from: @from, to: @to, body: 'Hi'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.fetch_inbox_for' do
|
48
|
+
it 'returns an inbox for the entity and configured store' do
|
49
|
+
store = double 'store'
|
50
|
+
Chatbox.configure { |config| config.store = store }
|
51
|
+
entity = double 'entity', chatbox_id: 1
|
52
|
+
expect(Chatbox.fetch_inbox_for(entity)).to eq Chatbox::Inbox.new(entity: entity, store: store)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '.fetch_outbox_for' do
|
57
|
+
it 'returns an outbox for the entity and configured store' do
|
58
|
+
store = double 'store'
|
59
|
+
Chatbox.configure { |config| config.store = store }
|
60
|
+
entity = double 'entity', chatbox_id: 1
|
61
|
+
expect(Chatbox.fetch_outbox_for(entity)).to eq Chatbox::Outbox.new(entity: entity, store: store)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'chatbox/draft'
|
2
|
+
|
3
|
+
describe Chatbox::Draft do
|
4
|
+
describe 'deliver!' do
|
5
|
+
it 'tells the store to add a message' do
|
6
|
+
store = double 'store'
|
7
|
+
draft = Chatbox::Draft.new(
|
8
|
+
from: double('entity', chatbox_id: 1),
|
9
|
+
to: double('entity', chatbox_id: 2),
|
10
|
+
body: 'Hi',
|
11
|
+
store: store,
|
12
|
+
)
|
13
|
+
expect(store).to receive(:add_message).with draft
|
14
|
+
draft.deliver!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
# More verbose output when running an individual spec file.
|
3
|
+
if config.files_to_run.one?
|
4
|
+
# Use the documentation formatter for detailed output,
|
5
|
+
# unless a formatter has already been configured
|
6
|
+
# (e.g. via a command-line flag).
|
7
|
+
config.default_formatter = 'doc'
|
8
|
+
end
|
9
|
+
|
10
|
+
# Print the 10 slowest examples and example groups at the
|
11
|
+
# end of the spec run, to help surface which specs are running
|
12
|
+
# particularly slow.
|
13
|
+
config.profile_examples = 10
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = :random
|
20
|
+
|
21
|
+
# rspec-expectations config goes here. You can use an alternate
|
22
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
23
|
+
# assertions if you prefer.
|
24
|
+
config.expect_with :rspec do |expectations|
|
25
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
26
|
+
# For more details, see:
|
27
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
28
|
+
expectations.syntax = :expect
|
29
|
+
end
|
30
|
+
|
31
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
32
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
33
|
+
config.mock_with :rspec do |mocks|
|
34
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
35
|
+
# For more details, see:
|
36
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
37
|
+
mocks.syntax = :expect
|
38
|
+
|
39
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
40
|
+
# a real object. This is generally recommended.
|
41
|
+
mocks.verify_partial_doubles = true
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chatbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Austin Schneider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-21 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- austinthecoder@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- chatbox.gemspec
|
84
|
+
- lib/chatbox.rb
|
85
|
+
- lib/chatbox/configuration.rb
|
86
|
+
- lib/chatbox/draft.rb
|
87
|
+
- lib/chatbox/inbox.rb
|
88
|
+
- lib/chatbox/memory_store.rb
|
89
|
+
- lib/chatbox/outbox.rb
|
90
|
+
- lib/chatbox/version.rb
|
91
|
+
- spec/chatbox_spec.rb
|
92
|
+
- spec/lib/draft_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
homepage: ''
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.2.2
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Simple messaging system.
|
118
|
+
test_files:
|
119
|
+
- spec/chatbox_spec.rb
|
120
|
+
- spec/lib/draft_spec.rb
|
121
|
+
- spec/spec_helper.rb
|