otp_kickoff 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,20 +1,14 @@
1
1
  = otp_kickoff
2
2
 
3
- Simple generator to kick off Erlang/OTP projects.
3
+ Simple generator to kick off Erlang/OTP projects quickly.
4
4
 
5
5
  == Install and configuration
6
6
 
7
- Install the gemcutter (a awesome gem hosting) support:
7
+ Install the otp_kickoff gem:
8
8
 
9
- sudo gem install gemcutter
9
+ sudo gem install otp_kickoff -s http://gemcutter.org
10
10
 
11
- More about gemcutter here http://gemcutter.org.
12
-
13
- Next, install the otp_kickoff:
14
-
15
- sudo gem install otp_kickoff
16
-
17
- Finally, configure your preferences:
11
+ And finally, configure your preferences:
18
12
 
19
13
  otp_kickoff configure --name=leandro --email=leandrodoze@gmail.com
20
14
 
@@ -41,6 +35,18 @@ That will generate:
41
35
 
42
36
  Enjoy a lot with Erlang/OTP programming!
43
37
 
38
+ == Help
39
+
40
+ If you need some help, type:
41
+
42
+ otp_kickoff help
43
+
44
+ For a specific command:
45
+
46
+ otp_kickoff help new_application
47
+
48
+ And so on...
49
+
44
50
  == Copyright
45
51
 
46
52
  Copyright (c) 2009 Leandro Silva. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/lib/otp_kickoff.rb CHANGED
@@ -6,6 +6,7 @@ require 'yaml'
6
6
  # Path to configuration file
7
7
  #
8
8
  CONFIGURATION_FILE = '~/.otp_kickoff'
9
+ TODAY = Date.today
9
10
 
10
11
  #
11
12
  # Thor classes, the magic of tasks!
@@ -29,12 +30,15 @@ class OTPKickOff < Thor
29
30
  # Tasks
30
31
  #
31
32
 
32
- no_tasks { attr_accessor :application_name, :author_name, :author_email, :today }
33
+ no_tasks { attr_accessor :author_name, :author_email }
34
+
35
+ no_tasks { attr_accessor :application_name, :supervisor_name, :server_name, :handler_name }
33
36
 
34
37
  # task: configure
35
38
 
36
- desc 'configure --author=AUTHOR --email=AUTHOR_EMAIL', 'configure informations about author'
37
- method_options :author => :string, :email => :string
39
+ desc 'configure', 'configure informations about author'
40
+ method_option :author, :type => :string, :required => true
41
+ method_option :email, :type => :string, :required => true
38
42
 
39
43
  def configure
40
44
  #set data about author
@@ -51,33 +55,85 @@ author_email: #{author_email}
51
55
 
52
56
  # task: new_application
53
57
 
54
- desc 'new_application --name=APPLICATION_NAME', 'generate a new Erlang/OTP application stub'
55
- method_options :name => :string
58
+ desc 'new_application', 'generate a new Erlang/OTP application stub'
59
+ method_option :name, :type => :string, :required => true, :aliases => "-n"
56
60
 
57
61
  def new_application
58
62
  # set data to templates
59
63
  @application_name = options[:name]
64
+ @supervisor_name = @application_name
65
+ @server_name = @application_name
60
66
 
61
- config_info = ConfigInfo.new
62
- @author_name = config_info.author_name
63
- @author_email = config_info.author_email
64
-
65
- @today = Date.today
66
-
67
+ @author_name, @author_email = get_config_info
68
+
67
69
  # generate templates
68
- template 'resources/template_app.app', "#{application_name}/src/#{application_name}_app.app"
70
+ template 'resources/template.app', "#{application_name}/src/#{application_name}.app"
69
71
  template 'resources/template_app.erl', "#{application_name}/src/#{application_name}_app.erl"
70
72
  template 'resources/template_sup.erl', "#{application_name}/src/#{application_name}_sup.erl"
71
73
  template 'resources/template_server.erl', "#{application_name}/src/#{application_name}_server.erl"
72
- template 'resources/template_handler.erl', "#{application_name}/src/#{application_name}_handler.erl"
73
74
  template 'resources/template_appstart.erl', "#{application_name}/src/#{application_name}.erl"
74
75
  template 'resources/template_include.hrl', "#{application_name}/src/#{application_name}.hrl"
75
-
76
+
76
77
  # create required directories
77
78
  empty_directory "#{application_name}/ebin"
78
79
  empty_directory "#{application_name}/deps"
79
80
  empty_directory "#{application_name}/priv"
80
81
  end
82
+
83
+ # task: new_supervisor
84
+
85
+ desc 'new_supervisor', 'generate a new Erlang/OTP supervisor stub'
86
+ method_option :name, :type => :string, :required => true, :aliases => "-n"
87
+ method_option :application_name, :type => :string, :required => true, :aliases => "-a"
88
+
89
+ def new_supervisor
90
+ # set data to templates
91
+ @supervisor_name = options[:name]
92
+ @application_name = options[:application_name]
93
+
94
+ @author_name, @author_email = get_config_info
95
+
96
+ # generate templates
97
+ template 'resources/template_sup.erl', "#{supervisor_name}_sup.erl"
98
+ end
99
+
100
+ # task: new_gen_server
101
+
102
+ desc 'new_gen_server', 'generate a new Erlang/OTP gen_server stub'
103
+ method_option :name, :type => :string, :required => true, :aliases => "-n"
104
+
105
+ def new_gen_server
106
+ # set data to templates
107
+ @server_name = options[:name]
108
+
109
+ @author_name, @author_email = get_config_info
110
+
111
+ # generate templates
112
+ template 'resources/template_server.erl', "#{server_name}_server.erl"
113
+ end
114
+
115
+ # task: new_gen_server
116
+
117
+ desc 'new_event_handler', 'generate a new Erlang/OTP gen_event handler stub'
118
+ method_option :name, :type => :string, :required => true, :aliases => "-n"
119
+
120
+ def new_event_handler
121
+ # set data to templates
122
+ @handler_name = options[:name]
123
+
124
+ @author_name, @author_email = get_config_info
125
+
126
+ # generate templates
127
+ template 'resources/template_handler.erl', "#{handler_name}_handler.erl"
128
+ end
129
+
130
+ private
131
+
132
+ def get_config_info
133
+ config_info = ConfigInfo.new
134
+
135
+ return config_info.author_name, config_info.author_email
136
+ end
81
137
  end
82
138
 
83
139
  #
data/otp_kickoff.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{otp_kickoff}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leandro Silva"]
12
- s.date = %q{2009-10-19}
12
+ s.date = %q{2009-12-05}
13
13
  s.default_executable = %q{otp_kickoff}
14
14
  s.email = %q{leandrodoze@gmail.com}
15
15
  s.executables = ["otp_kickoff"]
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  "bin/otp_kickoff",
28
28
  "lib/otp_kickoff.rb",
29
29
  "otp_kickoff.gemspec",
30
- "resources/template_app.app",
30
+ "resources/template.app",
31
31
  "resources/template_app.erl",
32
32
  "resources/template_appstart.erl",
33
33
  "resources/template_handler.erl",
@@ -63,3 +63,4 @@ Gem::Specification.new do |s|
63
63
  s.add_dependency(%q<thor>, [">= 0"])
64
64
  end
65
65
  end
66
+
@@ -1,16 +1,16 @@
1
1
  %%
2
2
  %% Resource application file
3
3
  %%
4
- %% File : <%=application_name%>_handler.erl
5
- %% Created: <%=Date.today%>
4
+ %% File : <%=application_name%>.app
5
+ %% Created: <%=TODAY%>
6
6
  %%
7
7
  %% @author <%=author_name%> <<%=author_email%>>
8
- %% @copyright <%=today.year%> <%=author_name%>
8
+ %% @copyright <%=TODAY.year%> <%=author_name%>
9
9
  %%
10
10
  %% @doc TODO make nice description
11
11
  %%
12
12
 
13
- {application, <%=application_name%>_app,
13
+ {application, <%=application_name%>,
14
14
  [{description, "<%=application_name.capitalize%> application version 1.0"},
15
15
  {vsn, "1.0"},
16
16
  {modules, [<%=application_name%>_sup, <%=application_name%>_app, <%=application_name%>_server]},
@@ -1,11 +1,11 @@
1
1
  %%
2
2
  %% Application module
3
3
  %%
4
- %% File : <%=application_name%>_handler.erl
5
- %% Created: <%=Date.today%>
4
+ %% File : <%=application_name%>_app.erl
5
+ %% Created: <%=TODAY%>
6
6
  %%
7
7
  %% @author <%=author_name%> <<%=author_email%>>
8
- %% @copyright <%=today.year%> <%=author_name%>
8
+ %% @copyright <%=TODAY.year%> <%=author_name%>
9
9
  %%
10
10
  %% @doc TODO make nice description
11
11
  %%
@@ -1,11 +1,11 @@
1
1
  %%
2
2
  %% Start application module
3
3
  %%
4
- %% File : <%=application_name%>_handler.erl
5
- %% Created: <%=Date.today%>
4
+ %% File : <%=application_name%>.erl
5
+ %% Created: <%=TODAY%>
6
6
  %%
7
7
  %% @author <%=author_name%> <<%=author_email%>>
8
- %% @copyright <%=today.year%> <%=author_name%>
8
+ %% @copyright <%=TODAY.year%> <%=author_name%>
9
9
  %%
10
10
  %% @doc TODO make nice description
11
11
  %%
@@ -1,35 +1,48 @@
1
1
  %%
2
- %% Handler module that can be used by server to catch and handle events
2
+ %% Handler module used by event manager to deal with events
3
3
  %%
4
- %% File : <%=application_name%>_handler.erl
5
- %% Created: <%=Date.today%>
4
+ %% File : <%=handler_name%>_handler.erl
5
+ %% Created: <%=TODAY%>
6
6
  %%
7
7
  %% @author <%=author_name%> <<%=author_email%>>
8
- %% @copyright <%=today.year%> <%=author_name%>
8
+ %% @copyright <%=TODAY.year%> <%=author_name%>
9
9
  %%
10
10
  %% @doc TODO make nice description
11
11
  %%
12
12
 
13
- -module(<%=application_name%>_handler).
13
+ -module(<%=handler_name%>_handler).
14
14
  -author('<%=author_name%> <<%=author_email%>>').
15
15
 
16
- -export([init/1, terminate/1, handle_event/2]).
16
+ -behahiour(gen_event).
17
+
18
+ -export([init/1, terminate/1, handle_event/2, handle_call/2, handle_info/2, code_change/3]).
17
19
 
18
20
  %% @spec init(State) -> State
19
- %% @doc Handler init callback
20
- init(State) -> State.
21
+ %% @doc Callback for initialize the <%=handler_name%>_handler
22
+ init(State) ->
23
+ {ok, State}.
21
24
 
22
- %% @spec terminate(State) -> State
23
- %% @doc Handler terminate callback
25
+ %% @spec terminate(State) -> {ok, State}
26
+ %% @doc Callback for cleanup the handler
24
27
  terminate(State) ->
25
28
  {ok, State}.
26
29
 
27
- %% @spec handle_event({event, _Event}, State) -> {ok, State}
28
- %% @doc Handle event function
29
- handle_event({event, _Event}, State) ->
30
- {ok, State};
31
-
32
- %% @spec handle_event(_Event, State) -> State
33
- %% @doc Handle event "catch" function
30
+ %% @spec handle_event(_Event, State) -> {ok, State}
31
+ %% @doc Callback for notified events on gen_event
34
32
  handle_event(_Event, State) ->
35
- State.
33
+ {ok, State}.
34
+
35
+ %% @spec handle_call(_Request, State) -> {ok, Reply, State}
36
+ %% @doc Callback for specific calls for this handler
37
+ handle_call(_Request, State) ->
38
+ {ok, noreply, State}.
39
+
40
+ %% @spec handle_info(_Info, State) -> {ok, State}
41
+ %% @doc Callback for unknow messages by the gen_event
42
+ handle_info(_Info, State) ->
43
+ {ok, State}.
44
+
45
+ %% @spec code_change(_OldVsn, State, _Extra) -> {ok, State}
46
+ %% @doc Callback for update internal state during upgrade/downgrade
47
+ code_change(_OldVsn, State, _Extra) ->
48
+ {ok, State}.
@@ -1,11 +1,11 @@
1
1
  %%
2
2
  %% Include file
3
3
  %%
4
- %% File : <%=application_name%>_handler.erl
5
- %% Created: <%=Date.today%>
4
+ %% File : <%=application_name%>_include.erl
5
+ %% Created: <%=TODAY%>
6
6
  %%
7
7
  %% @author <%=author_name%> <<%=author_email%>>
8
- %% @copyright <%=today.year%> <%=author_name%>
8
+ %% @copyright <%=TODAY.year%> <%=author_name%>
9
9
  %%
10
10
  %% @doc TODO make nice description
11
11
  %%
@@ -1,16 +1,16 @@
1
1
  %%
2
2
  %% Supervised worker process module
3
3
  %%
4
- %% File : <%=application_name%>_handler.erl
5
- %% Created: <%=Date.today%>
4
+ %% File : <%=server_name%>_server.erl
5
+ %% Created: <%=TODAY%>
6
6
  %%
7
7
  %% @author <%=author_name%> <<%=author_email%>>
8
- %% @copyright <%=today.year%> <%=author_name%>
8
+ %% @copyright <%=TODAY.year%> <%=author_name%>
9
9
  %%
10
10
  %% @doc TODO make nice description
11
11
  %%
12
12
 
13
- -module(<%=application_name%>_server).
13
+ -module(<%=server_name%>_server).
14
14
  -author('<%=author_name%> <<%=author_email%>>').
15
15
 
16
16
  -behaviour(gen_server).
@@ -26,22 +26,17 @@
26
26
  %% Operation & Maintenance API
27
27
  %%
28
28
 
29
- %% @spec start_link() -> ServerReturn
30
- %% @doc Start the server for <%=application_name%>
29
+ %% @spec start_link() -> {ok, Pid}
30
+ %% @doc Start the <%=server_name%>_server
31
31
  start_link() ->
32
32
  gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
33
-
34
- %% @spec stop() -> ServerReturn
35
- %% @doc Stopt the server for <%=application_name%>
36
- stop() ->
37
- gen_server:cast(?MODULE, stop).
38
33
 
39
34
  %%
40
35
  %% Genserver callback functions
41
36
  %%
42
37
 
43
38
  %% @spec init(State) -> {ok, State}
44
- %% @doc Callback for initialize the server
39
+ %% @doc Callback for initialize the <%=server_name%>_server
45
40
  init(State) ->
46
41
  {ok, State}.
47
42
 
@@ -62,7 +57,7 @@ handle_cast(_Msg, State) ->
62
57
  {noreply, State}.
63
58
 
64
59
  %% @spec handle_info(_Info, State) -> {noreply, State}
65
- %% @doc Callback for give informations about server
60
+ %% @doc Callback for timeout or other unreconized messages
66
61
  handle_info(_Info, State) ->
67
62
  {noreply, State}.
68
63
 
@@ -1,16 +1,16 @@
1
1
  %%
2
2
  %% Supervisor module
3
3
  %%
4
- %% File : <%=application_name%>_handler.erl
5
- %% Created: <%=Date.today%>
4
+ %% File : <%=supervisor_name%>_sup.erl
5
+ %% Created: <%=TODAY%>
6
6
  %%
7
7
  %% @author <%=author_name%> <<%=author_email%>>
8
- %% @copyright <%=today.year%> <%=author_name%>
8
+ %% @copyright <%=TODAY.year%> <%=author_name%>
9
9
  %%
10
10
  %% @doc TODO make nice description
11
11
  %%
12
12
 
13
- -module(<%=application_name%>_sup).
13
+ -module(<%=supervisor_name%>_sup).
14
14
  -author('<%=author_name%> <<%=author_email%>>').
15
15
 
16
16
  -behaviour(supervisor).
@@ -27,8 +27,8 @@
27
27
  %% Operation & Maintenance API
28
28
  %%
29
29
 
30
- %% @spec start_link() -> SupervisorReturn
31
- %% @doc Start the supervisor for <%=application_name%>
30
+ %% @spec start_link() -> {ok, Pid}
31
+ %% @doc Start the <%=supervisor_name%>_sup for <%=application_name%> application
32
32
  start_link() ->
33
33
  supervisor:start_link({local, ?SERVER}, ?MODULE, []).
34
34
 
@@ -36,12 +36,12 @@ start_link() ->
36
36
  %% Supervisor callback function
37
37
  %%
38
38
 
39
- %% @spec init([]) -> SupervisorSpec
40
- %% @doc Callback for initialize the supervisor for <%=application_name%>
39
+ %% @spec init([]) -> {ok, {{RestartStrategy, MaxRestart, MaxTime}, [ChildSpec]}}
40
+ %% @doc Callback for initialize the <%=supervisor_name%>_sup for <%=application_name%> application
41
41
  init([]) ->
42
42
  %% <%=application_name%>_server is a supervisioned child process
43
- Server = {<%=application_name%>_server_child,
44
- {<%=application_name%>_server, start_link, []},permanent, 2000, worker, [<%=application_name%>_server]},
43
+ Server = {<%=application_name%>_server,
44
+ {<%=application_name%>_server, start_link, []}, permanent, brutal_kill, worker, [<%=application_name%>_server]},
45
45
 
46
46
  %% Restart strategies for childs
47
47
  {ok, {{one_for_one, 10, 1}, [Server]}}.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otp_kickoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Silva
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-19 00:00:00 -07:00
12
+ date: 2009-12-05 00:00:00 -08:00
13
13
  default_executable: otp_kickoff
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,7 +51,7 @@ files:
51
51
  - bin/otp_kickoff
52
52
  - lib/otp_kickoff.rb
53
53
  - otp_kickoff.gemspec
54
- - resources/template_app.app
54
+ - resources/template.app
55
55
  - resources/template_app.erl
56
56
  - resources/template_appstart.erl
57
57
  - resources/template_handler.erl