preplay-event 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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/lib/preplay/event.rb +115 -0
- data/lib/preplay/event/version.rb +5 -0
- data/preplay-event.gemspec +24 -0
- data/spec/fixtures/guess_updated_event.txt +1 -0
- data/spec/preplay/event_spec.rb +58 -0
- data/spec/spec_helper.rb +5 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f3f07a01e8f9b9c780924adb6cd051425d76c77
|
4
|
+
data.tar.gz: d7d23c5cff6653a4694b5f95114859c4b89f1da1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce5d64b2896634aa934bac937f12f23242cc35f10fbbdd2f09bfe8106e6a6e96f3f6ec4742329903a5274025ee86de90e0a637d9d93ba044550f89417c3c0809
|
7
|
+
data.tar.gz: deb9dcad75f74e827ddcfc25461c1895a15194cc22eaed28694de99695299ac445855b416853abf87e84bdc119064e86028fd1b1f1d856fba6b76b8c7d251317
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
#guard :rspec, cli: '--color --format doc', all_on_start: false, all_after_pass: false do
|
5
|
+
guard :rspec, cli: '--color --format doc' do
|
6
|
+
watch(%r{^(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jérémy Van de Wyngaert
|
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,29 @@
|
|
1
|
+
# Preplay::Event
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'preplay-event'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install preplay-event
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/preplay-event/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module PrePlay
|
2
|
+
|
3
|
+
def self.Event(event_type, data = {}, context = {}, opts = nil)
|
4
|
+
e = Event.new(
|
5
|
+
{
|
6
|
+
'type' => event_type
|
7
|
+
}.merge(filter(data, event_type)),
|
8
|
+
context,
|
9
|
+
{
|
10
|
+
'dyno'=> $dyno_name,
|
11
|
+
'created_at'=> Time.now.to_s
|
12
|
+
}
|
13
|
+
)
|
14
|
+
e.to_scrolls(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
#will filter the hash that was given to keep only the data that we want to display on the logs depending on the data type
|
18
|
+
def self.filter(data, event_type)
|
19
|
+
return {} unless PrePlay::Event.configuration.field_whitelist.has_key?(event_type)
|
20
|
+
data.select {|k| PrePlay::Event.configuration.field_whitelist[event_type].include?(k)}
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
class Event < Struct.new :data, :context, :metadata
|
25
|
+
|
26
|
+
class Configuration
|
27
|
+
attr_accessor :field_whitelist
|
28
|
+
def initialize
|
29
|
+
yield self if block_given?
|
30
|
+
|
31
|
+
@field_whitelist ||= {}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.configure(&block)
|
36
|
+
configuration(&block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.configuration(&block)
|
40
|
+
@@configuration ||= Configuration.new(&block)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
def to_scrolls(opts = nil)
|
46
|
+
event = {
|
47
|
+
'd' => data,
|
48
|
+
'c' => context,
|
49
|
+
'm' => metadata
|
50
|
+
}
|
51
|
+
flatten_keys(event).merge!(preplay_event: true)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
#this "flatten" a hash in order to use it on a Scrolls.log line
|
57
|
+
# {
|
58
|
+
# data: {
|
59
|
+
# foo: 'bar',
|
60
|
+
# baz: 42
|
61
|
+
# }
|
62
|
+
# }
|
63
|
+
# become :
|
64
|
+
# {
|
65
|
+
# :'data.foo' => 'bar',
|
66
|
+
# :'data.baz' => 42
|
67
|
+
# }
|
68
|
+
def flatten_keys(hash, namespace = nil)
|
69
|
+
namespace = namespace.nil? ? '' : "#{namespace}."
|
70
|
+
hash.inject(Hash.new) do |result, key, value|
|
71
|
+
|
72
|
+
hash.each do |k, v|
|
73
|
+
if v.is_a? Hash
|
74
|
+
# recursive call with the new namespace
|
75
|
+
result.merge! flatten_keys(v, namespace + k.to_s)
|
76
|
+
else
|
77
|
+
# direct set in the hash of the v
|
78
|
+
result["#{namespace}#{k}".to_sym] = v
|
79
|
+
end
|
80
|
+
end
|
81
|
+
result
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.parse(log_line)
|
86
|
+
data = Shellwords.shellsplit(log_line)
|
87
|
+
from_hash Hash[data.map{|el| el.split('=')}]
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.from_hash(hash)
|
91
|
+
@data = {
|
92
|
+
'data' => {},
|
93
|
+
'context' => {},
|
94
|
+
'metadata' => {}
|
95
|
+
}
|
96
|
+
|
97
|
+
hash.each do |k, v|
|
98
|
+
prefix, key = k.to_s.split('.', 2)
|
99
|
+
next unless %w(d c m).include? prefix
|
100
|
+
|
101
|
+
event_part = case prefix
|
102
|
+
when 'd' then @data['data']
|
103
|
+
when 'c' then @data['context']
|
104
|
+
when 'm' then @data['metadata']
|
105
|
+
end
|
106
|
+
|
107
|
+
event_part[key] = v
|
108
|
+
end
|
109
|
+
|
110
|
+
Event.new(@data['data'], @data['context'], @data['metadata'])
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'preplay/event'
|
5
|
+
require 'preplay/event/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "preplay-event"
|
9
|
+
spec.version = PrePlay::Event::VERSION
|
10
|
+
spec.authors = ["Jérémy Van de Wyngaert"]
|
11
|
+
spec.email = ["jeremyvdw@gmail.com"]
|
12
|
+
spec.summary = "PrePlay::Event is a marshal/unmarshal event lib made to pass events through logs"
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14.0"
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
process_name=web.1-child-6 source=mlb_integration req_id=e63a865c-02a1-493c-a313-979ede6ab597 d.type=guess_updated d.choice=5/3 d.id="stanko:final_score:fake_gid_2014_03_27_tbamlb_balmlb_1_90446" c.user_id=stanko c.game_id=fake_gid_2014_03_27_tbamlb_balmlb_1_90446 c.guess_opportunity_id="final_score:fake_gid_2014_03_27_tbamlb_balmlb_1_90446" m.dyno=nil m.created_at="01 April 2014 04:03 PM" preplay_event=true count#guess.updated=1
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PrePlay::Event do
|
4
|
+
|
5
|
+
let(:now) { Time.now.to_s }
|
6
|
+
before do
|
7
|
+
allow(Time).to receive(:now).and_return(now)
|
8
|
+
|
9
|
+
PrePlay::Event.configure do |c|
|
10
|
+
c.field_whitelist = { 'user_follow' => %w{id username} }.freeze
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { PrePlay::Event(_event_type, _data, _context) }
|
15
|
+
|
16
|
+
let(:_event_type) do
|
17
|
+
'user_follow'
|
18
|
+
end
|
19
|
+
let(:_data) do
|
20
|
+
{
|
21
|
+
'id' => 'johndoe',
|
22
|
+
'username' => 'john_doe',
|
23
|
+
'forbidden' => 'content'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
let(:_context) do
|
27
|
+
{
|
28
|
+
'some' => 'context'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:hash) do
|
33
|
+
{:"d.type"=>"user_follow", :"d.id"=>"johndoe", :"d.username"=>"john_doe", :"c.some"=>"context", :"m.dyno"=>nil, :"m.created_at"=>now, :'preplay_event'=>true}
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#to_scrolls" do
|
37
|
+
it { expect(subject).to eq(hash) }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Event" do
|
41
|
+
subject { PrePlay::Event.from_hash hash }
|
42
|
+
|
43
|
+
its(:data) { should include({ 'id' => 'johndoe', 'username' => 'john_doe' }) }
|
44
|
+
its(:context) { should include(_context) }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".from_hash" do
|
48
|
+
subject { PrePlay::Event.from_hash hash }
|
49
|
+
|
50
|
+
it { expect(subject).to eq(described_class.new({'type'=> 'user_follow', 'id'=>'johndoe', 'username'=> 'john_doe'}, {'some'=> 'context'}, {'dyno'=> nil, 'created_at'=> now})) }
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ".parse" do
|
54
|
+
subject { PrePlay::Event.parse load_fixture('guess_updated_event.txt') }
|
55
|
+
|
56
|
+
it { expect(subject).to eq PrePlay::Event.new({"type"=>"guess_updated", "choice"=>"5/3", "id"=>"stanko:final_score:fake_gid_2014_03_27_tbamlb_balmlb_1_90446"}, {"user_id"=>"stanko", "game_id"=>"fake_gid_2014_03_27_tbamlb_balmlb_1_90446", "guess_opportunity_id"=> "final_score:fake_gid_2014_03_27_tbamlb_balmlb_1_90446"}, {"dyno"=>"nil", "created_at"=>"01 April 2014 04:03 PM"}) }
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: preplay-event
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jérémy Van de Wyngaert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-03 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: 2.14.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.0
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jeremyvdw@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- Guardfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/preplay/event.rb
|
69
|
+
- lib/preplay/event/version.rb
|
70
|
+
- preplay-event.gemspec
|
71
|
+
- spec/fixtures/guess_updated_event.txt
|
72
|
+
- spec/preplay/event_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: ''
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: PrePlay::Event is a marshal/unmarshal event lib made to pass events through
|
98
|
+
logs
|
99
|
+
test_files:
|
100
|
+
- spec/fixtures/guess_updated_event.txt
|
101
|
+
- spec/preplay/event_spec.rb
|
102
|
+
- spec/spec_helper.rb
|