evil_events 0.1.0rc3 → 0.1.0rc4

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: 6ba90c2963630dfa0bd968c6da4fccc798c72e8a
4
- data.tar.gz: b403a12b2797da58c9d08271a6f8350faa4ecc9f
3
+ metadata.gz: c736b2f681a527cc5c3f01b2463954b8206864a2
4
+ data.tar.gz: 5de17389672409a9a313820d9b1dbdbdbc86d17e
5
5
  SHA512:
6
- metadata.gz: 944e8fe8086ec3e38fd8267a1aa0b5d7c0505357053d55b9cfd814ebf309c25b46c505f1fdb668ba86b00d04a2cc8e4fe3f6cb2ef3559489e1264016254f98f5
7
- data.tar.gz: 323332e087b6d55203956b33161cac1e694dc905e9dbc54e414d2895ea795d1f50df3beba53d5ec1cfb2af80809190122040ee00a30c2ee17b501de5807d844a
6
+ metadata.gz: c570fc9dedbdf9b8ee66cbf735a59d89cfe2ffc33e70c6a0b1e6866388379a06acd9ccd836e718ab9530d4626e04cb0d679891dbdd97b66c69d28f6cf1207079
7
+ data.tar.gz: 0c65ec58f6114b0a469307920ba246eea79f0642b9e68ba8be75b2267886bb6778b1b9c2aeeb8b64b200ba4119c60cd5545b42ed0aabd5546adab7cff68fb848
data/README.md CHANGED
@@ -1,10 +1,57 @@
1
- # EvilEvents - event subsystem for ruby applications
1
+ # EvilEvents :imp: - event subsystem for ruby applications (work in progress!)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/evil_events.svg)](https://badge.fury.io/rb/evil_events)
4
4
  [![Build Status](https://travis-ci.org/ergosploit/evil_events.svg?branch=master)](https://travis-ci.org/ergosploit/evil_events)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/ergosploit/evil_events/badge.svg?branch=master)](https://coveralls.io/github/ergosploit/evil_events?branch=master)
6
6
 
7
- NOTE: Work in progress!
7
+ ### Proof of Concept
8
+
9
+ ```ruby
10
+ # 0. Subscribers:
11
+ EventStore = Concurrent::Array.new
12
+ ElasticStore = Concurrent::Array.new
13
+
14
+ # 1. Create events:
15
+ class UserRegistered < EvilEvents::Event['user_registered']
16
+ payload :user_id, EvilEvents::Types::Strict::Int
17
+ payload :ref_link, EvilEvents::Types::Strict::String.default('undefined')
18
+
19
+ metadata :uuid, EvilEvents::Types::String.default('shared-uuid')
20
+ metadata :timestamp, EvilEvents::Types::Time.default { Time.now }
21
+
22
+ observe EventStore, delegator: :push
23
+ observe ElasticStore, delegator: :<<
24
+
25
+ adapter :memory_async
26
+ end
27
+
28
+ MatchLost = EvilEvents::Event.define('match_lost') do
29
+ default_delegator :push
30
+
31
+ payload :player_id
32
+ payload :score
33
+
34
+ metadata :timestamp, EvilEvents::Types::Time.default { Time.now }
35
+
36
+ observe EventStore
37
+
38
+ adapter :memory_sync
39
+ end
40
+
41
+ # 2. Emit via object or via event attributes:
42
+ UserRegistered.new(payload: { user_id: 1, ref_id: 5 }, metadata: { uuid: 1_111 }).emit!
43
+ EvilEvents::Event.emit('user_registered', payload: { user_id: 2, ref_id: 7 })
44
+ EvilEvents::Event.emit('match_lost', payload: { player_id: 5, score: '2-1' })
45
+
46
+ # 3. Logs:
47
+ # => INFO -- [EvilEvents:EventEmitted(memory_async)]: Type: user_registered :: Payload: {:user_id=>1, :ref_id=>5} :: Metadata: {:uuid=>1111, :timestamp=>2017-10-15 20:08:09 +0300}
48
+ # => INFO -- [EvilEvents:EventEmitted(memory_async)]: Type: user_registered :: Payload: {:user_id=>2, :ref_id=>7} :: Metadata: {:uuid=>"shared-uuid", :timestamp=>2017-10-15 20:08:09 +0300}
49
+ # => INFO -- [EvilEvents:EventEmitted(memory_sync)]: Type: match_lost :: Payload: {:player_id=>5, :score=>"2-1"} :: Metadata: {:timestamp=>2017-10-15 20:08:09 +0300}
50
+
51
+ # 4. State of observers:
52
+ EventStore # => [#<UserRegistered...>, #<UserRegistered...>, <#MatchLost...>]
53
+ ElasticStore # => [#<UserRegistered...>, #<UserRegistered...>]
54
+ ```
8
55
 
9
56
  ### ROADMAP
10
57
  - Basic documentation (README) (0.1.0)
data/evil_events.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.summary = 'Event subsystem for ruby applications'
17
17
  spec.description = 'Ultra simple, but very flexible and fully customizable event subsystem ' \
18
18
  'for ruby applications with a wide set of customization interfaces ' \
19
- ' and smart event definition DSL.'
19
+ 'and smart event definition DSL.'
20
20
 
21
21
  spec.bindir = 'bin'
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -26,15 +26,16 @@ Gem::Specification.new do |spec|
26
26
  f.match(%r{^(spec|features)/})
27
27
  end
28
28
 
29
- spec.add_dependency 'dry-types', '0.12.0'
29
+ spec.add_dependency 'dry-monads', '0.3.1'
30
+ spec.add_dependency 'dry-types', '0.12.1'
30
31
  spec.add_dependency 'dry-struct', '0.3.1'
31
32
  spec.add_dependency 'dry-configurable', '0.7.0'
32
33
  spec.add_dependency 'dry-container', '0.6.0'
33
34
  spec.add_dependency 'concurrent-ruby', '1.0.5'
34
35
 
35
- spec.add_development_dependency 'coveralls', '0.7.2'
36
+ spec.add_development_dependency 'coveralls', '0.8.21'
36
37
  spec.add_development_dependency 'pry', '0.11.1'
37
- spec.add_development_dependency 'simplecov', '0.15.1'
38
+ spec.add_development_dependency 'simplecov', '0.14.1'
38
39
  spec.add_development_dependency 'simplecov-json', '0.2'
39
40
  spec.add_development_dependency 'rubocop', '0.50.0'
40
41
  spec.add_development_dependency 'bundler', '1.15.4'
@@ -4,6 +4,7 @@ module EvilEvents::Shared
4
4
  # @api public
5
5
  # @since 0.1.0
6
6
  module Types
7
+ Dry::Types.load_extensions(:maybe)
7
8
  include Dry::Types.module
8
9
  end
9
10
  end
@@ -25,6 +25,22 @@ class EvilEvents::System
25
25
  event_type
26
26
  )
27
27
  end
28
+
29
+ # @param serialized_event [String]
30
+ # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
31
+ #
32
+ # @since 0.1.0
33
+ def deserialize_from_json(serialized_event)
34
+ EvilEvents::Core::Events::Serializer.resolve[:json].deserialize(serialized_event)
35
+ end
36
+
37
+ # @param serialized_event [Hash]
38
+ # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
39
+ #
40
+ # @since 0.1.0
41
+ def deserialize_from_hash(serialized_event)
42
+ EvilEvents::Core::Events::Serializer.resolve[:hash].deserialize(serialized_event)
43
+ end
28
44
  end
29
45
  end
30
46
  end
@@ -67,6 +67,14 @@ class EvilEvents::System
67
67
  # @since 0.1.0
68
68
  def define_abstract_event_class(event_type); end
69
69
 
70
+ # @see EvilEvents::System
71
+ # @since 0.1.0
72
+ def deserialize_from_json(serialized_event); end
73
+
74
+ # @see EvilEvents::System
75
+ # @since 0.1.0
76
+ def deserialize_from_hash(serialized_event); end
77
+
70
78
  # @see EvilEvents::System
71
79
  # @since 0.1.0
72
80
  def managed_event?(event_class); end
@@ -38,7 +38,9 @@ class EvilEvents::System
38
38
  # @since 0.1.0
39
39
  def_delegators 'EvilEvents::System::EventBuilder',
40
40
  :define_event_class,
41
- :define_abstract_event_class
41
+ :define_abstract_event_class,
42
+ :deserialize_from_json,
43
+ :deserialize_from_hash
42
44
 
43
45
  # @return [EvilEvents::System::Broadcaster]
44
46
  #
@@ -3,5 +3,5 @@
3
3
  module EvilEvents
4
4
  # @api public
5
5
  # @since 0.1.0
6
- VERSION = '0.1.0rc3'
6
+ VERSION = '0.1.0rc4'
7
7
  end
data/lib/evil_events.rb CHANGED
@@ -19,35 +19,60 @@ module EvilEvents
19
19
  require_relative 'evil_events/boot_point'
20
20
  require_relative 'evil_events/version'
21
21
 
22
+ # @api public
22
23
  # @since 0.1.0
23
24
  Types = Shared::Types
24
25
 
25
- class << self
26
- # @see EvilEvents::System
27
- # @api public
28
- # @since 0.1.0
29
- def [](event_type)
30
- EvilEvents::BootPoint[:event_system].define_abstract_event_class(
31
- event_type
32
- )
33
- end
26
+ # @api public
27
+ # @since 0.1.0
28
+ module Serializer
29
+ class << self
30
+ # @see EvilEvents::System
31
+ # @api public
32
+ # @since 0.1.0
33
+ def load_from_json(serialized_event)
34
+ EvilEvents::BootPoint[:event_system].deserialize_from_json(serialized_event)
35
+ end
34
36
 
35
- # @see EvilEvents::System
36
- # @api public
37
- # @since 0.1.0
38
- def define_event(event_type, &event_class_definitions)
39
- EvilEvents::BootPoint[:event_system].define_event_class(
40
- event_type, &event_class_definitions
41
- )
37
+ # @see EvilEvents::System
38
+ # @api public
39
+ # @since 0.1.0
40
+ def load_from_hash(serialized_event)
41
+ EvilEvents::BootPoint[:event_system].deserialize_from_hash(serialized_event)
42
+ end
42
43
  end
44
+ end
45
+
46
+ # @api public
47
+ # @since 0.1.0
48
+ module Event
49
+ class << self
50
+ # @see EvilEvents::System
51
+ # @api public
52
+ # @since 0.1.0
53
+ def [](event_type)
54
+ EvilEvents::BootPoint[:event_system].define_abstract_event_class(
55
+ event_type
56
+ )
57
+ end
58
+
59
+ # @see EvilEvents::System
60
+ # @api public
61
+ # @since 0.1.0
62
+ def define(event_type, &event_class_definitions)
63
+ EvilEvents::BootPoint[:event_system].define_event_class(
64
+ event_type, &event_class_definitions
65
+ )
66
+ end
43
67
 
44
- # @see EvilEvents::System
45
- # @api public
46
- # @since 0.1.0
47
- def emit(event_type, **event_attributes)
48
- EvilEvents::BootPoint[:event_system].raw_emit(
49
- event_type, **event_attributes
50
- )
68
+ # @see EvilEvents::System
69
+ # @api public
70
+ # @since 0.1.0
71
+ def emit(event_type, **event_attributes)
72
+ EvilEvents::BootPoint[:event_system].raw_emit(
73
+ event_type, **event_attributes
74
+ )
75
+ end
51
76
  end
52
77
  end
53
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evil_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0rc3
4
+ version: 0.1.0rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
@@ -10,20 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-monads
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: dry-types
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - '='
18
32
  - !ruby/object:Gem::Version
19
- version: 0.12.0
33
+ version: 0.12.1
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - '='
25
39
  - !ruby/object:Gem::Version
26
- version: 0.12.0
40
+ version: 0.12.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: dry-struct
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - '='
88
102
  - !ruby/object:Gem::Version
89
- version: 0.7.2
103
+ version: 0.8.21
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - '='
95
109
  - !ruby/object:Gem::Version
96
- version: 0.7.2
110
+ version: 0.8.21
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: pry
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +128,14 @@ dependencies:
114
128
  requirements:
115
129
  - - '='
116
130
  - !ruby/object:Gem::Version
117
- version: 0.15.1
131
+ version: 0.14.1
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - '='
123
137
  - !ruby/object:Gem::Version
124
- version: 0.15.1
138
+ version: 0.14.1
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: simplecov-json
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -207,7 +221,7 @@ dependencies:
207
221
  - !ruby/object:Gem::Version
208
222
  version: 1.18.0
209
223
  description: Ultra simple, but very flexible and fully customizable event subsystem
210
- for ruby applications with a wide set of customization interfaces and smart event
224
+ for ruby applications with a wide set of customization interfaces and smart event
211
225
  definition DSL.
212
226
  email: iamdaiver@icloud.com
213
227
  executables: []