seh 0.0.3 → 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.
data/.gitignore CHANGED
@@ -3,3 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  *~
6
+ .yardoc/*
7
+ doc/*
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --no-private
2
+ --markup="markdown"
3
+ --main README.md
data/Gemfile CHANGED
@@ -4,5 +4,4 @@ group :development, :test do
4
4
  gem 'rspec'
5
5
  end
6
6
 
7
- # Specify your gem's dependencies in seh.gemspec
8
7
  gemspec
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+
2
+ # seh: structured event handler
3
+
4
+ ## Roadmap
5
+ * documentation
6
+ * unit tests (my bad)
7
+ * examples
8
+
9
+ ## v0.1.0
10
+ seh API is fully implemented :)
11
+
12
+ ## Contact
13
+ Please send (welcome) feedback and bug reports to ryan.berckmans@gmail.com.
data/lib/seh.rb CHANGED
@@ -5,17 +5,17 @@ require "seh/event"
5
5
 
6
6
  module Seh
7
7
  class << self
8
- # alias for Seh::EventType::And
8
+ # @note alias of {EventType::And}
9
9
  def and( *types )
10
10
  EventType::And.new *types
11
11
  end
12
12
 
13
- # alias for Seh::EventType::Or
13
+ # @note alias of {EventType::Or}
14
14
  def or( *types )
15
15
  EventType::Or.new *types
16
16
  end
17
17
 
18
- # alias for Seh::EventType::Not
18
+ # @note alias of {EventType::Not}
19
19
  def not( type )
20
20
  EventType::Not.new type
21
21
  end
data/lib/seh/event.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'ostruct'
2
2
 
3
3
  module Seh
4
- module Private # :nodoc: all
4
+ # @private
5
+ module Private
5
6
  START = 0
6
7
  BEFORE = 100
7
8
 
@@ -18,10 +19,11 @@ module Seh
18
19
  FINISH = 1000
19
20
 
20
21
  class EventData
21
- attr_accessor :types, :target, :time, :staged_handlers, :success
22
+ attr_accessor :types, :type_map, :target, :time, :staged_handlers, :success
22
23
 
23
24
  def initialize
24
25
  @types = []
26
+ @type_map = {}
25
27
  @target = nil
26
28
  @time = Time.now
27
29
  @success = true
@@ -35,6 +37,26 @@ module Seh
35
37
  class << self
36
38
  def type( data, t )
37
39
  data.types << t
40
+ apply_type_map data
41
+ end
42
+
43
+ def type_map( data, map = {} )
44
+ map.each_pair do |type, implied_types|
45
+ data.type_map[type] ||= []
46
+ data.type_map[type].concat implied_types
47
+ data.type_map[type].uniq!
48
+ end
49
+ apply_type_map data
50
+ end
51
+
52
+ private
53
+ def apply_type_map( data )
54
+ while true
55
+ original_size = data.types.size
56
+ data.type_map.each_pair { |type, implied_types| data.types.concat implied_types if data.types.include? type }
57
+ data.types.uniq!
58
+ break if original_size = data.types.size
59
+ end
38
60
  end
39
61
  end
40
62
  end
@@ -66,7 +88,7 @@ module Seh
66
88
  end
67
89
 
68
90
  def dispatch
69
- raise "Event may only be dispatched once" unless @state == Private::EventStateReady
91
+ raise "Event#dispatch may only be called once" unless @state == Private::EventStateReady
70
92
  @state = Private::EventStateInflight
71
93
  collect_targets.each { |t| t.each_bind { |bind| bind.block.call self if bind.event_type.match @data.types } }
72
94
  @data.staged_handlers.each_key.sort.each { |stage| @data.staged_handlers[stage].each { |block| block.call self } }
@@ -79,6 +101,12 @@ module Seh
79
101
 
80
102
  def type( event_type )
81
103
  @state.type @data, event_type
104
+ nil
105
+ end
106
+
107
+ def type_map( map )
108
+ @state.type_map @data, map
109
+ nil
82
110
  end
83
111
 
84
112
  def match_type( event_type )
@@ -21,7 +21,8 @@ module Seh
21
21
  end
22
22
  end
23
23
 
24
- module Private # :nodoc: all
24
+ # @private
25
+ module Private
25
26
  class EventBind
26
27
  attr_reader :event_type, :block
27
28
 
data/lib/seh/version.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module Seh
2
- VERSION = "0.0.3" # :nodoc:
2
+ # @private
3
+ VERSION = "0.1.0"
3
4
  end
data/seh.gemspec CHANGED
@@ -8,16 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Ryan Berckmans"]
9
9
  s.email = ["ryan.berckmans@gmail.com"]
10
10
  s.homepage = "https://github.com/ryanberckmans/seh"
11
- s.summary = "pure ruby event handling similar to w3c dom events; pre-alpha wip"
12
- s.description = "Pure ruby event handling similar to w3c dom events. Lots of bells and whistles to support complex event handling as required by stuff like video games.
13
- + event handling in a synchronous specific order
14
- + event targets can have multiple parents and common ancestors; event propagation does a breadth first search traversal over a directed acyclic event target graph
15
- + staged callbacks: event.before { .. }; event.after { .. }
16
- + staged callbacks allow for an ancestor to influence affect of event on a descendant: ancestor.before { |event| event.x = 5 }; descendant.after { |event| puts event.x }
17
- + events can have multiple types, and types can inherit from other types
18
- + bind callbacks using event type filtering: node.bind(overcast AND (rain OR snow)) { |event| callback! }
19
- + optional event failure: event.success { yay! }; event.failure { oops! }
20
- + events on stack don't care about other events above/below - event A, currently executing, can create/dispatch/finish another event B"
11
+ s.summary = "Structured event handler. Pure ruby event handling similar to w3c dom events; alpha wip."
12
+ s.description = "#{s.summary} Lots of bells and whistles to support complex event handling as required by stuff like video games. Event handling in a synchronous specific order. Events 'bubble', and event targets can have multiple parents and common ancestors. Staged event callbacks: event.before { 'the united states of' }; event.after { 'america' }. Staged callbacks allow an ancestor to influence affect of event on a descendant: ancestor.before { |event| event.damage *= 2 }; descendant.after { |event| player.health -= event.damage }. Events use 'tag-style' types: event.type :hostile ; event.type :spell. Handle only events which pass a filter: player.bind( Seh::and :hostile, Seh::not( :spell ) ) { |event| 'Hostile non-spell!!' }. Optional event failure: event.fail; event.success { 'yay!' }; event.failure { 'oops!' }. Event inherits from OpenStruct for dynamic properties: event.omgs = 'omgs a dynamic attribute'"
21
13
 
22
14
  s.rubyforge_project = "seh"
23
15
 
@@ -25,9 +17,4 @@ Gem::Specification.new do |s|
25
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
19
  s.require_paths = ["lib"]
28
-
29
- s.has_rdoc = true
30
- s.rdoc_options << '--title' << 'Seh - Structured Event Handling' \
31
- << '--main' << 'README.org'
32
- s.extra_rdoc_files = ['README.org']
33
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,42 +9,32 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-17 00:00:00.000000000Z
12
+ date: 2011-06-19 00:00:00.000000000Z
13
13
  dependencies: []
14
- description: ! 'Pure ruby event handling similar to w3c dom events. Lots of bells
15
- and whistles to support complex event handling as required by stuff like video games.
16
-
17
- + event handling in a synchronous specific order
18
-
19
- + event targets can have multiple parents and common ancestors; event propagation
20
- does a breadth first search traversal over a directed acyclic event target graph
21
-
22
- + staged callbacks: event.before { .. }; event.after { .. }
23
-
24
- + staged callbacks allow for an ancestor to influence affect of event on a descendant:
25
- ancestor.before { |event| event.x = 5 }; descendant.after { |event| puts event.x
26
- }
27
-
28
- + events can have multiple types, and types can inherit from other types
29
-
30
- + bind callbacks using event type filtering: node.bind(overcast AND (rain OR snow))
31
- { |event| callback! }
32
-
33
- + optional event failure: event.success { yay! }; event.failure { oops! }
34
-
35
- + events on stack don''t care about other events above/below - event A, currently
36
- executing, can create/dispatch/finish another event B'
14
+ description: ! 'Structured event handler. Pure ruby event handling similar to w3c
15
+ dom events; alpha wip. Lots of bells and whistles to support complex event handling
16
+ as required by stuff like video games. Event handling in a synchronous specific
17
+ order. Events ''bubble'', and event targets can have multiple parents and common
18
+ ancestors. Staged event callbacks: event.before { ''the united states of'' }; event.after
19
+ { ''america'' }. Staged callbacks allow an ancestor to influence affect of event
20
+ on a descendant: ancestor.before { |event| event.damage *= 2 }; descendant.after
21
+ { |event| player.health -= event.damage }. Events use ''tag-style'' types: event.type
22
+ :hostile ; event.type :spell. Handle only events which pass a filter: player.bind(
23
+ Seh::and :hostile, Seh::not( :spell ) ) { |event| ''Hostile non-spell!!'' }. Optional
24
+ event failure: event.fail; event.success { ''yay!'' }; event.failure { ''oops!''
25
+ }. Event inherits from OpenStruct for dynamic properties: event.omgs = ''omgs a
26
+ dynamic attribute'''
37
27
  email:
38
28
  - ryan.berckmans@gmail.com
39
29
  executables: []
40
30
  extensions: []
41
- extra_rdoc_files:
42
- - README.org
31
+ extra_rdoc_files: []
43
32
  files:
44
33
  - .gitignore
45
34
  - .rvmrc
35
+ - .yardopts
46
36
  - Gemfile
47
- - README.org
37
+ - README.md
48
38
  - Rakefile
49
39
  - lib/seh.rb
50
40
  - lib/seh/event.rb
@@ -56,11 +46,7 @@ files:
56
46
  homepage: https://github.com/ryanberckmans/seh
57
47
  licenses: []
58
48
  post_install_message:
59
- rdoc_options:
60
- - --title
61
- - Seh - Structured Event Handling
62
- - --main
63
- - README.org
49
+ rdoc_options: []
64
50
  require_paths:
65
51
  - lib
66
52
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -80,5 +66,6 @@ rubyforge_project: seh
80
66
  rubygems_version: 1.8.5
81
67
  signing_key:
82
68
  specification_version: 3
83
- summary: pure ruby event handling similar to w3c dom events; pre-alpha wip
69
+ summary: Structured event handler. Pure ruby event handling similar to w3c dom events;
70
+ alpha wip.
84
71
  test_files: []
data/README.org DELETED
@@ -1,4 +0,0 @@
1
-
2
- * seh: structured event handler
3
-
4
-