event_machine 0.2.0 → 0.3.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/README.rdoc +18 -28
- data/VERSION +1 -1
- data/event_machine.gemspec +23 -30
- data/generators/event_machine/USAGE +2 -2
- data/generators/event_machine/event_machine_generator.rb +22 -34
- data/generators/event_machine/templates/event.rb +3 -3
- data/generators/event_machine/templates/functional_test.rb +5 -5
- metadata +36 -53
- data/.gitignore +0 -21
data/README.rdoc
CHANGED
@@ -1,40 +1,34 @@
|
|
1
1
|
= event_machine
|
2
|
-
|
3
|
-
when user posts a blog, you need to notice all of his friends, but it's really urgly to do like this:
|
2
|
+
With event machine, you can keep an eye on any action on your rails controller, say in your sns website, when user posts a blog, you need to notice all of his friends, but it's really urgly to do like this:
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
notice_all_friends
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
</pre>
|
4
|
+
BlogController:
|
5
|
+
def create
|
6
|
+
# new and save code
|
7
|
+
notice_all_friends
|
8
|
+
end
|
9
|
+
end
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
we'd beeter have an observer on the action, the code in the make_friends action block only concerns about building
|
21
|
-
relationship between the two people, the observer then notice other people, and this is also what IoC(AOP) teach us.
|
11
|
+
let's take another scenario, in your sns site, when one user makes friends with the other one, we should notice all friends of these two people, but how to?
|
12
|
+
we'd beeter have an observer on the action, the code in the make_friends action block only concerns about building relationship between the two people, the observer then notice other people, and this is also what IoC(AOP) teach us.
|
22
13
|
|
23
14
|
Usage:
|
24
15
|
|
25
16
|
in your config/environment.rb:
|
26
17
|
|
27
|
-
|
18
|
+
gem "event_machine", :version => ">=0.2.1"
|
19
|
+
|
20
|
+
application_controller.rb:
|
21
|
+
|
22
|
+
class ApplicationController < ActionController::Base
|
23
|
+
include EventMachine
|
24
|
+
end
|
28
25
|
|
29
26
|
and the generate command :
|
30
27
|
|
31
|
-
|
32
|
-
~your_project_path> script/generate event_machine create_favorite FavoriteController create
|
33
|
-
</pre>
|
28
|
+
~your_project_path> rails g event_machine create_favorite FavoriteController create
|
34
29
|
|
35
30
|
then it will generate a event file which content like following:
|
36
31
|
|
37
|
-
<pre>
|
38
32
|
|
39
33
|
for_action FavoritesController, :create do
|
40
34
|
|
@@ -48,15 +42,13 @@ then it will generate a event file which content like following:
|
|
48
42
|
|
49
43
|
end
|
50
44
|
|
51
|
-
</pre>
|
52
45
|
|
53
46
|
now you can add your code in the block and after block, enjoy.
|
54
47
|
|
55
48
|
= to observe multiple actions
|
56
49
|
|
57
|
-
|
50
|
+
to observe multiple actions, you should:
|
58
51
|
|
59
|
-
<pre>
|
60
52
|
for_actions [[FavoritesController, :create], [BlogsController,:create]] do
|
61
53
|
|
62
54
|
before do
|
@@ -69,8 +61,6 @@ now you can add your code in the block and after block, enjoy.
|
|
69
61
|
|
70
62
|
end
|
71
63
|
|
72
|
-
</pre>
|
73
|
-
|
74
64
|
|
75
65
|
== Note on Patches/Pull Requests
|
76
66
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/event_machine.gemspec
CHANGED
@@ -1,52 +1,45 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "event_machine"
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["tim.teng"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-12-07"
|
13
|
+
s.description = "Event Machine is observer to record any action you want to keep an eye on"
|
14
|
+
s.email = "tim.rubist@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"test/test_event_machine.rb"
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"event_machine.gemspec",
|
26
|
+
"generators/event_machine/USAGE",
|
27
|
+
"generators/event_machine/event_machine_generator.rb",
|
28
|
+
"generators/event_machine/templates/event.rb",
|
29
|
+
"generators/event_machine/templates/functional_test.rb",
|
30
|
+
"lib/event_machine.rb",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_event_machine.rb"
|
34
33
|
]
|
35
|
-
s.homepage =
|
36
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.homepage = "http://github.com/tteng/event_machine"
|
37
35
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version =
|
39
|
-
s.summary =
|
40
|
-
s.test_files = [
|
41
|
-
"test/test_event_machine.rb",
|
42
|
-
"test/helper.rb"
|
43
|
-
]
|
36
|
+
s.rubygems_version = "1.8.10"
|
37
|
+
s.summary = "an observer to record events"
|
44
38
|
|
45
39
|
if s.respond_to? :specification_version then
|
46
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
40
|
s.specification_version = 3
|
48
41
|
|
49
|
-
if Gem::Version.new(Gem::
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
43
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
51
44
|
else
|
52
45
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
@@ -1,2 +1,2 @@
|
|
1
|
-
Usage:
|
2
|
-
Example:
|
1
|
+
Usage: rails g event_machine EventName Controller Action
|
2
|
+
Example: rails g event_machine media_rated Admin::ContentController rate_media
|
@@ -1,43 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def initialize(runtime_args, runtime_options = {})
|
4
|
-
super
|
5
|
-
@event_name = runtime_args.shift
|
6
|
-
@controller_name = runtime_args.shift
|
7
|
-
@controller_action = runtime_args.shift
|
8
|
-
unless valid_options?
|
9
|
-
puts "Invalid arguments!"
|
10
|
-
puts banner
|
11
|
-
exit
|
12
|
-
end
|
13
|
-
end
|
1
|
+
#coding: utf-8
|
2
|
+
require 'fileutils'
|
14
3
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
m.template "functional_test.rb",
|
24
|
-
File.join('test/functional/events', "#{@event_name}Event".underscore + "_test.rb"),
|
25
|
-
:assigns => { :controller => @controller_name,
|
26
|
-
:action => @controller_action,
|
27
|
-
:event => "#{@event_name}Event"
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
4
|
+
class EventMachineGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
argument :this_event_name, :type => :string
|
9
|
+
argument :controller_name, :type => :string
|
10
|
+
argument :action_name, :type => :string
|
31
11
|
|
32
|
-
def
|
33
|
-
"
|
34
|
-
"
|
12
|
+
def generate_event
|
13
|
+
template "event.rb", "app/events/#{parsed_event_name}_event.rb"
|
14
|
+
template "functional_test.rb", "test/functional/events/#{parsed_event_name}_test.rb"
|
35
15
|
end
|
36
16
|
|
37
17
|
private
|
38
18
|
|
39
|
-
def
|
40
|
-
|
19
|
+
def parsed_event_name
|
20
|
+
this_event_name.underscore
|
21
|
+
end
|
22
|
+
|
23
|
+
def parsed_controller_name
|
24
|
+
controller_name.camelize
|
25
|
+
end
|
26
|
+
|
27
|
+
def parsed_action_name
|
28
|
+
action_name.underscore
|
41
29
|
end
|
42
30
|
|
43
31
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
for_action <%=
|
1
|
+
for_action <%= parsed_controller_name %>Controller, :<%= action_name %> do
|
2
2
|
|
3
3
|
before do
|
4
|
-
# This will be called before <%=
|
4
|
+
# This will be called before <%= parsed_controller_name %>#<%= parsed_action_name %>
|
5
5
|
end
|
6
6
|
|
7
7
|
after do
|
8
|
-
# This will be called after <%=
|
8
|
+
# This will be called after <%= parsed_controller_name %>#<%= parsed_action_name %>
|
9
9
|
end
|
10
10
|
|
11
11
|
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../test_helper'
|
2
2
|
require File.dirname(__FILE__) + '/../../functional/events/events_base_test'
|
3
|
-
require '<%=
|
3
|
+
require '<%= parsed_controller_name.underscore -%>_controller'
|
4
4
|
|
5
5
|
# Re-raise errors caught by the controller.
|
6
|
-
class <%=
|
6
|
+
class <%= parsed_controller_name -%>; def rescue_action(e) raise e end; end
|
7
7
|
|
8
|
-
class <%=
|
8
|
+
class <%= parsed_event_name.camelize -%>Test < EventBaseTest
|
9
9
|
|
10
10
|
fixtures :users
|
11
11
|
|
12
12
|
def setup
|
13
|
-
@controller = <%=
|
13
|
+
@controller = <%= parsed_controller_name.camelize-%>.new
|
14
14
|
@request = ActionController::TestRequest.new
|
15
15
|
@response = ActionController::TestResponse.new
|
16
16
|
|
17
17
|
prepare
|
18
|
-
load_event "
|
18
|
+
load_event "app/events/<%= parsed_event_name-%>_event.rb"
|
19
19
|
emulate_login
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,46 +1,37 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_machine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
version: 0.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- tim.teng
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-07 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: thoughtbot-shoulda
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 0
|
29
|
-
version: "0"
|
16
|
+
requirement: &70149382639540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
30
22
|
type: :development
|
31
|
-
|
32
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70149382639540
|
25
|
+
description: Event Machine is observer to record any action you want to keep an eye
|
26
|
+
on
|
33
27
|
email: tim.rubist@gmail.com
|
34
28
|
executables: []
|
35
|
-
|
36
29
|
extensions: []
|
37
|
-
|
38
|
-
extra_rdoc_files:
|
30
|
+
extra_rdoc_files:
|
39
31
|
- LICENSE
|
40
32
|
- README.rdoc
|
41
|
-
files:
|
33
|
+
files:
|
42
34
|
- .document
|
43
|
-
- .gitignore
|
44
35
|
- LICENSE
|
45
36
|
- README.rdoc
|
46
37
|
- Rakefile
|
@@ -53,36 +44,28 @@ files:
|
|
53
44
|
- lib/event_machine.rb
|
54
45
|
- test/helper.rb
|
55
46
|
- test/test_event_machine.rb
|
56
|
-
has_rdoc: true
|
57
47
|
homepage: http://github.com/tteng/event_machine
|
58
48
|
licenses: []
|
59
|
-
|
60
49
|
post_install_message:
|
61
|
-
rdoc_options:
|
62
|
-
|
63
|
-
require_paths:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
64
52
|
- lib
|
65
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
- 0
|
78
|
-
version: "0"
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
79
65
|
requirements: []
|
80
|
-
|
81
66
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.8.10
|
83
68
|
signing_key:
|
84
69
|
specification_version: 3
|
85
70
|
summary: an observer to record events
|
86
|
-
test_files:
|
87
|
-
- test/test_event_machine.rb
|
88
|
-
- test/helper.rb
|
71
|
+
test_files: []
|