event_machine 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,40 +1,34 @@
1
1
  = event_machine
2
- With event machine, you can keep an eye on any action on your rails controller, say in your sns website,
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
- <pre>
6
-
7
- BlogController:
8
-
9
- def create
10
- # new and save code
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
- let's take another scenario, in your sns site, when one user makes friends with the other one, we should notice
19
- all friends of these two people, but how to?
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
- config.gem "event_machine", :version => ">=0.2.0"
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
- <pre>
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
- to observe multiple actions, you should:
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.2.0
1
+ 0.3.0
@@ -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 the gemspec command
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 = %q{event_machine}
8
- s.version = "0.2.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 = %q{2010-05-12}
13
- s.description = %q{Event Machine is observer to record any action you want to keep an eye on}
14
- s.email = %q{tim.rubist@gmail.com}
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
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "event_machine.gemspec",
27
- "generators/event_machine/USAGE",
28
- "generators/event_machine/event_machine_generator.rb",
29
- "generators/event_machine/templates/event.rb",
30
- "generators/event_machine/templates/functional_test.rb",
31
- "lib/event_machine.rb",
32
- "test/helper.rb",
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 = %q{http://github.com/tteng/event_machine}
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 = %q{1.3.6}
39
- s.summary = %q{an observer to record events}
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::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
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: ./script/generate event EventName Controller Action
2
- Example: ./script/generate event media_rated Admin::ContentController rate_media
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
- class EventMachineGenerator < Rails::Generator::NamedBase
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
- def manifest
16
- record do |m|
17
- m.directory "app/events"
18
- m.directory "test/functional/events"
19
- m.template "event.rb",
20
- File.join('app/events', "#{@event_name}Event".underscore + ".rb"),
21
- :assigns => { :controller => @controller_name, :action => @controller_action }
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 banner
33
- "Usage: #{$0} event EventName Controller Action"
34
- "Example: #{$0} event media_rated Admin::ContentController rate"
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 valid_options?
40
- [@event_name, @controller_name, @controller_action].all? { |v| !v.blank? }
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 <%= controller %>, :<%= action %> do
1
+ for_action <%= parsed_controller_name %>Controller, :<%= action_name %> do
2
2
 
3
3
  before do
4
- # This will be called before <%= controller %>#<%= action %>
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 <%= controller %>#<%= action %>
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 '<%= controller.underscore -%>'
3
+ require '<%= parsed_controller_name.underscore -%>_controller'
4
4
 
5
5
  # Re-raise errors caught by the controller.
6
- class <%= controller.classify -%>; def rescue_action(e) raise e end; end
6
+ class <%= parsed_controller_name -%>; def rescue_action(e) raise e end; end
7
7
 
8
- class <%= event.classify -%>Test < EventBaseTest
8
+ class <%= parsed_event_name.camelize -%>Test < EventBaseTest
9
9
 
10
10
  fixtures :users
11
11
 
12
12
  def setup
13
- @controller = <%= controller.classify -%>.new
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 "#{EVENTS_DIR}/<%= event.underscore -%>.rb"
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
- prerelease: false
5
- segments:
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
- date: 2010-05-12 00:00:00 +08:00
18
- default_executable:
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
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
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
- version_requirements: *id001
32
- description: Event Machine is observer to record any action you want to keep an eye on
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
- - --charset=UTF-8
63
- require_paths:
50
+ rdoc_options: []
51
+ require_paths:
64
52
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- segments:
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.3.6
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: []
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC