streamline 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -5
- data/lib/generators/streamline/stores/templates/active_record/create_events.rb.tt +1 -3
- data/lib/streamline.rb +0 -1
- data/lib/streamline/stores/active_record_store.rb +1 -5
- data/lib/streamline/stores/base_store.rb +0 -4
- data/lib/streamline/version.rb +1 -1
- data/spec/lib/streamline/jobs/handle_event_job_spec.rb +6 -91
- data/spec/spec_helper.rb +0 -1
- data/spec/support/models.rb +1 -3
- data/spec/support/store_examples.rb +1 -1
- data/streamline.gemspec +0 -2
- metadata +2 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96df0fff0c9d69ff55d765607f44313c9cb2e6ea
|
4
|
+
data.tar.gz: 2a139d717a813da7b97865794391ac0f5eab3973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17597e0b643b68fe5043711332a46d17df2658283b4d56ef8849286be8c209cca1be942bf16c2f7ea74775635e0340f8aeec41d784bc8e04dbd15f34be5062fa
|
7
|
+
data.tar.gz: 02dd2c67218e9343f0058e9504989481345790fc520fb89d7e34c0dbdb27e2958ef42a325ed33082caaf63e6d50e37134749ba534efd81644c878a3850bcd000
|
data/README.md
CHANGED
@@ -1,7 +1,73 @@
|
|
1
|
-
#
|
1
|
+
# Streamline
|
2
2
|
|
3
|
-
|
4
|
-
[![Code Climate](https://codeclimate.com/github/atipugin/airplane/badges/gpa.svg)](https://codeclimate.com/github/atipugin/airplane)
|
5
|
-
[![Build Status](https://travis-ci.org/atipugin/airplane.svg?branch=master)](https://travis-ci.org/atipugin/airplane)
|
3
|
+
**Important! It's still early proof-of-concept. Use it on your own risk ;)**
|
6
4
|
|
7
|
-
|
5
|
+
Streamline allows you to organize event-based behavior of your app way more simpler.
|
6
|
+
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/streamline.svg)](https://badge.fury.io/rb/streamline)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/atipugin/streamline/badges/gpa.svg)](https://codeclimate.com/github/atipugin/streamline)
|
9
|
+
[![Build Status](https://travis-ci.org/atipugin/streamline.svg?branch=master)](https://travis-ci.org/atipugin/streamline)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add to your Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'streamline'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
```shell
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it system-wide:
|
26
|
+
|
27
|
+
```
|
28
|
+
$ gem install streamline
|
29
|
+
```
|
30
|
+
|
31
|
+
## Setup
|
32
|
+
|
33
|
+
First of all, you have to select a [data store](#data-stores) for your events. Let's take ActiveRecord store for example:
|
34
|
+
|
35
|
+
```shell
|
36
|
+
$ rails generate streamline:stores:active_record
|
37
|
+
```
|
38
|
+
|
39
|
+
It will generate all neccessary files (a model and migration file in this case).
|
40
|
+
|
41
|
+
Next, you need to configure ActiveJob adapter (if you haven't done it yet). Streamline uses background jobs a lot and usage of ActiveJob allows us to support [as many queuing backends as possible](http://edgeguides.rubyonrails.org/active_job_basics.html#backends).
|
42
|
+
|
43
|
+
Imagine your app already uses Sidekiq. Just add the following line to your `application.rb`:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
config.active_job.queue_adapter = :sidekiq
|
47
|
+
```
|
48
|
+
|
49
|
+
Then add `streamline` queue to your `sidekiq.yml`.
|
50
|
+
|
51
|
+
You're almost done! It's time to set up handlers and track some events.
|
52
|
+
|
53
|
+
## Handlers
|
54
|
+
|
55
|
+
...
|
56
|
+
|
57
|
+
## Event tracking
|
58
|
+
|
59
|
+
...
|
60
|
+
|
61
|
+
## Data stores
|
62
|
+
|
63
|
+
Streamline supports following event stores:
|
64
|
+
|
65
|
+
- ActiveRecord (PostgreSQL, MySQL, SQLite etc)
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it
|
70
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
71
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
72
|
+
4. Push to the branch (git push origin my-new-feature)
|
73
|
+
5. Create new Pull Request
|
@@ -1,14 +1,12 @@
|
|
1
1
|
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :streamline_events
|
4
|
-
t.uuid :id, primary_key: true
|
3
|
+
create_table :streamline_events do |t|
|
5
4
|
t.string :name, null: false
|
6
5
|
t.<%= postgresql? ? (jsonb? ? 'jsonb' : 'json') : 'text' %> :properties
|
7
6
|
t.datetime :occurred_at, null: false
|
8
7
|
t.references :target, polymorphic: true
|
9
8
|
end
|
10
9
|
|
11
|
-
add_index :streamline_events, :id
|
12
10
|
add_index :streamline_events, [:target_type, :target_id]
|
13
11
|
end
|
14
12
|
end
|
data/lib/streamline.rb
CHANGED
data/lib/streamline/version.rb
CHANGED
@@ -5,102 +5,17 @@ module Streamline
|
|
5
5
|
include_context 'handler'
|
6
6
|
|
7
7
|
let(:handler) { Streamline.registry[event_name].sample }
|
8
|
-
let(:subsequent_events) { Streamline.store.find_subsequent_events(event) }
|
9
8
|
let(:params) { { event_id: event_id, handler: handler } }
|
9
|
+
let(:params_dump) { YAML.dump(params) }
|
10
10
|
|
11
11
|
before do
|
12
|
-
handler_class.handle
|
12
|
+
handler_class.handle(event_name, handler_options)
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '#
|
16
|
-
it '
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#if_satisfied?' do
|
23
|
-
let(:handler_options) { { if: FFaker::Lorem.word } }
|
24
|
-
|
25
|
-
it 'returns false' do
|
26
|
-
expect(subject.send(:if_satisfied?, handler, subsequent_events))
|
27
|
-
.to be(false)
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when expected event is occurred' do
|
31
|
-
before do
|
32
|
-
Streamline.store.save_event(
|
33
|
-
event_attributes.merge(
|
34
|
-
name: handler_options[:if],
|
35
|
-
occurred_at: 1.minute.from_now
|
36
|
-
)
|
37
|
-
)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns true' do
|
41
|
-
expect(subject.send(:if_satisfied?, handler, subsequent_events))
|
42
|
-
.to be(true)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#unless_satisfied?' do
|
48
|
-
let(:handler_options) { { unless: FFaker::Lorem.word } }
|
49
|
-
|
50
|
-
it 'returns true' do
|
51
|
-
expect(subject.send(:unless_satisfied?, handler, subsequent_events))
|
52
|
-
.to be(true)
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when unexpected event is occurred' do
|
56
|
-
before do
|
57
|
-
Streamline.store.save_event(
|
58
|
-
event_attributes.merge(
|
59
|
-
name: handler_options[:unless],
|
60
|
-
occurred_at: 1.minute.from_now
|
61
|
-
)
|
62
|
-
)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'returns false' do
|
66
|
-
expect(subject.send(:unless_satisfied?, handler, subsequent_events))
|
67
|
-
.to be(false)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe '#apply_constraints' do
|
73
|
-
let(:event_properties) { { user_id: rand(1..10) } }
|
74
|
-
let(:handler_options) { { constraints: :user_id } }
|
75
|
-
|
76
|
-
before do
|
77
|
-
Streamline.store.save_event(
|
78
|
-
event_attributes.merge(occurred_at: 1.minute.from_now)
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'returns suitable events' do
|
83
|
-
expect(
|
84
|
-
subject
|
85
|
-
.send(:apply_constraints, handler, event, subsequent_events)
|
86
|
-
.sample['properties']
|
87
|
-
).to include('user_id' => event_properties[:user_id])
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#enqueue_repeat' do
|
92
|
-
it 'does not enqueue itself again' do
|
93
|
-
expect { subject.send(:enqueue_repeat, handler, params) }
|
94
|
-
.not_to enqueue_a(described_class)
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when amount of handler repeats is greater than one' do
|
98
|
-
let(:handler_options) { { repeats: 2 } }
|
99
|
-
|
100
|
-
it 'enqueues itself again' do
|
101
|
-
expect { subject.send(:enqueue_repeat, handler, params) }
|
102
|
-
.to enqueue_a(described_class)
|
103
|
-
end
|
15
|
+
describe '#perform' do
|
16
|
+
it 'runs handler' do
|
17
|
+
allow_any_instance_of(handler_class).to receive(:run).with(event)
|
18
|
+
subject.perform(params_dump)
|
104
19
|
end
|
105
20
|
end
|
106
21
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/models.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
2
2
|
|
3
3
|
ActiveRecord::Schema.define do
|
4
|
-
create_table :streamline_events
|
5
|
-
t.uuid :id, primary_key: true
|
4
|
+
create_table :streamline_events do |t|
|
6
5
|
t.string :name, null: false
|
7
6
|
t.text :properties
|
8
7
|
t.datetime :occurred_at, null: false
|
9
8
|
t.references :target, polymorphic: true
|
10
9
|
end
|
11
10
|
|
12
|
-
add_index :streamline_events, :id
|
13
11
|
add_index :streamline_events, [:target_type, :target_id]
|
14
12
|
end
|
15
13
|
|
data/streamline.gemspec
CHANGED
@@ -14,10 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.require_paths = %w(lib)
|
15
15
|
|
16
16
|
spec.add_dependency 'activejob'
|
17
|
-
spec.add_dependency 'activesupport'
|
18
17
|
|
19
18
|
spec.add_development_dependency 'activerecord'
|
20
|
-
spec.add_development_dependency 'activeuuid'
|
21
19
|
spec.add_development_dependency 'database_cleaner'
|
22
20
|
spec.add_development_dependency 'ffaker'
|
23
21
|
spec.add_development_dependency 'pry'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streamline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Tipugin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activesupport
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: activerecord
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +38,6 @@ dependencies:
|
|
52
38
|
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activeuuid
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: database_cleaner
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|