Sutto-marvin 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 4
2
+ patch: 0
3
3
  major: 0
4
- minor: 2
4
+ minor: 3
@@ -1,5 +1,10 @@
1
1
  # Use this class to debug stuff as you
2
2
  # go along - e.g. dump events etc.
3
- class DebugHandler < Marvin::Base
3
+ class DebugHandler < Marvin::CommandHandler
4
4
 
5
+ exposes :about
6
+ def about(*args)
7
+ reply "Marvin v#{Marvin::VERSION::STRING} running on Ruby #{RUBY_VERSION} (#{RUBY_PLATFORM})"
8
+ end
9
+
5
10
  end
@@ -10,8 +10,8 @@ require 'marvin/exceptions'
10
10
  module Marvin
11
11
  module VERSION
12
12
  MAJOR = 0
13
- MINOR = 1
14
- PATCH = 20081120
13
+ MINOR = 3
14
+ PATCH = 0
15
15
 
16
16
  STRING = [MAJOR, MINOR, PATCH].join(".")
17
17
  end
@@ -21,6 +21,8 @@ module Marvin
21
21
  autoload :Distributed, 'marvin/distributed'
22
22
  autoload :AbstractClient, 'marvin/abstract_client'
23
23
  autoload :Base, 'marvin/base'
24
+ autoload :Console, 'marvin/console'
25
+ autoload :CoreCommands, 'marvin/core_commands'
24
26
  autoload :ClientMixin, 'marvin/client_mixin'
25
27
  autoload :Settings, 'marvin/settings'
26
28
  autoload :Logger, 'marvin/logger'
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module Marvin
2
4
 
3
5
  # A Simple Marvin handler based on processing
@@ -5,15 +7,19 @@ module Marvin
5
7
  class CommandHandler < Base
6
8
 
7
9
  class_inheritable_accessor :exposed_methods, :command_prefix
10
+ cattr_accessor :descriptions, :last_description, :exposed_method_names
8
11
 
9
- self.command_prefix = ""
10
- self.exposed_methods = []
12
+ self.command_prefix = ""
13
+ self.exposed_methods = Set.new
14
+ self.descriptions = {}
15
+ self.exposed_method_names = Set.new
11
16
 
12
17
  class << self
13
18
 
14
19
  def exposes(*args)
15
- self.exposed_methods ||= []
16
- self.exposed_methods += args.map { |a| a.to_sym }.flatten
20
+ names = args.map { |a| a.to_sym }.flatten
21
+ self.exposed_methods += names
22
+ self.exposed_method_names += names
17
23
  end
18
24
 
19
25
  end
@@ -54,6 +60,21 @@ module Marvin
54
60
  end
55
61
  end
56
62
 
63
+ class << self
64
+
65
+ def desc(desc)
66
+ self.last_description = desc
67
+ end
68
+
69
+ def method_added(name)
70
+ unless last_description.blank?
71
+ descriptions[name.to_sym] = self.last_description
72
+ self.last_description = nil
73
+ end
74
+ end
75
+
76
+ end
77
+
57
78
  end
58
79
 
59
80
  end
@@ -1,54 +1,77 @@
1
- MARVIN_ROOT = File.join(File.dirname(__FILE__), "../..")
2
- Marvin::Settings.verbose = true
3
- Marvin::Settings.log_level = :debug
4
- Marvin::Settings.default_client = Marvin::TestClient
5
- Marvin::Loader.run! :console
6
-
7
- def parse(line)
8
- Marvin::Settings.default_parser.parse(line)
9
- end
10
-
11
- def logger
12
- Marvin::Logger.logger
13
- end
14
-
15
- def client
16
- $client ||= Marvin::Settings.default_client.new(:port => 6667, :server => "irc.freenode.net")
17
- end
18
-
19
- class ServerMock < Marvin::IRC::Server::BaseConnection
20
- def send_line(line)
21
- puts ">> #{line}"
22
- end
23
- def kill_connection!
24
- puts "Killing connection"
25
- end
26
-
27
- def get_peername
28
- # Localhost, HTTP
29
- "\034\036\000P\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000"
30
- end
31
-
32
- def host
33
- "localhost"
34
- end
35
-
36
- def port
37
- 6667
38
- end
39
-
40
- end
41
-
42
- def server(reset = false)
43
- $server = ServerMock.new(:port => 6667, :host => "localhost") if $server.blank? || reset
44
- return $server
45
- end
46
-
47
- def user(reset = false)
48
- unless @user_created || reset
49
- server.receive_line "NICK SuttoL"
50
- server.receive_line "USER SuttoL 0 * :SuttoL"
51
- @user_created = true
1
+ require 'irb'
2
+
3
+ module Marvin
4
+ class Console
5
+
6
+ module BaseExtensions
7
+ def parse(line)
8
+ Marvin::Settings.default_parser.parse(line)
9
+ end
10
+
11
+ def logger
12
+ Marvin::Logger.logger
13
+ end
14
+
15
+ def client
16
+ $client ||= Marvin::Settings.default_client.new(:port => 6667, :server => "irc.freenode.net")
17
+ end
18
+
19
+ class ServerMock < Marvin::IRC::Server::BaseConnection
20
+ def send_line(line)
21
+ puts ">> #{line}"
22
+ end
23
+ def kill_connection!
24
+ puts "Killing connection"
25
+ end
26
+
27
+ def get_peername
28
+ # Localhost, HTTP
29
+ "\034\036\000P\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000"
30
+ end
31
+
32
+ def host
33
+ "localhost"
34
+ end
35
+
36
+ def port
37
+ 6667
38
+ end
39
+
40
+ end
41
+
42
+ def server(reset = false)
43
+ $server = ServerMock.new(:port => 6667, :host => "localhost") if $server.blank? || reset
44
+ return $server
45
+ end
46
+
47
+ def user(reset = false)
48
+ unless @user_created || reset
49
+ server.receive_line "NICK SuttoL"
50
+ server.receive_line "USER SuttoL 0 * :SuttoL"
51
+ @user_created = true
52
+ end
53
+ return server.connection_implementation
54
+ end
55
+ end
56
+
57
+ def initialize(file = $0)
58
+ @file = file
59
+ setup_irb
60
+ end
61
+
62
+ def setup_irb
63
+ # This is a bit hacky, surely there is a better way?
64
+ # e.g. some way to specify which scope irb runs in.
65
+ eval("include Marvin::Console::BaseExtensions", TOPLEVEL_BINDING)
66
+ end
67
+
68
+ def run
69
+ IRB.start(@file)
70
+ end
71
+
72
+ def self.run
73
+ self.new.run
74
+ end
75
+
52
76
  end
53
- return server.connection_implementation
54
77
  end
@@ -13,7 +13,7 @@ module Marvin
13
13
  :server => Marvin::IRC::Server,
14
14
  :ring_server => Marvin::Distributed::RingServer,
15
15
  :distributed_client => Marvin::Distributed::DRbClient,
16
- :console => nil
16
+ :console => Marvin::Console
17
17
  }
18
18
 
19
19
  # For each of the known types, define a method
@@ -80,11 +80,11 @@ module Marvin
80
80
 
81
81
  def run!
82
82
  self.register_signals
83
- Marvin::Options.parse! unless self.type == :console
83
+ Marvin::Options.parse!
84
84
  Marvin::Daemon.daemonize! if Marvin::Settings.daemon?
85
85
  Marvin::Logger.setup
86
86
  self.load_settings
87
- require(Marvin::Settings.root / "config/setup")
87
+ require(Marvin::Settings.root / "config" / "setup")
88
88
  self.load_handlers
89
89
  self.class.invoke_hooks! :before_run
90
90
  attempt_controller_action! :run
@@ -138,7 +138,10 @@ module Marvin
138
138
 
139
139
  # Register to the Marvin::DataStore methods
140
140
  if Marvin::Loader.client?
141
- before_run { Marvin::DataStore.load! }
141
+ before_run do
142
+ Marvin::CoreCommands.register!
143
+ Marvin::DataStore.load!
144
+ end
142
145
  after_stop { Marvin::DataStore.dump! }
143
146
  end
144
147
 
@@ -18,9 +18,9 @@ module Marvin
18
18
  o.separator ""
19
19
  o.separator ""
20
20
  o.on("-l", "--level=[level]", String, "The log level to use",
21
- "Default: #{options[:log_level]}") {|options[:log_level]|}
22
- o.on("-v", "--verbose", "Be verbose (print to stdout)") {|options[:verbose]|}
23
- o.on("-d", "--daemon", "Run as a daemon (drop the PID)") {|options[:daemon]|}
21
+ "Default: #{options[:log_level]}") {|v| options[:log_level] = v}
22
+ o.on("-v", "--verbose", "Be verbose (print to stdout)") {|v| options[:verbose] = v}
23
+ o.on("-d", "--daemon", "Run as a daemon (drop the PID)") {|v| options[:daemon] = v}
24
24
  o.on("-k", "--kill", "Kill all of the current type / the running instances") do |kill|
25
25
  if kill
26
26
  Marvin::Daemon.kill_all(Marvin::Loader.type)
@@ -1,9 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- libs = ["-r irb/completion", "-r lib/marvin", "-r lib/marvin/console"]
4
-
5
- cmd = "irb #{libs.join(" ")} --simple-prompt"
6
-
7
- puts "Loading Marvin console..."
8
-
9
- exec cmd
2
+ require File.join(File.dirname(__FILE__), "..", "config", "boot")
3
+ Marvin::Loader.run! :console
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Sutto-marvin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darcy Laycock
@@ -14,6 +14,7 @@ default_executable: marvin
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: activesupport
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -32,6 +34,7 @@ dependencies:
32
34
  version:
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: eventmachine
37
+ type: :runtime
35
38
  version_requirement:
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
@@ -41,6 +44,7 @@ dependencies:
41
44
  version:
42
45
  - !ruby/object:Gem::Dependency
43
46
  name: thor
47
+ type: :runtime
44
48
  version_requirement:
45
49
  version_requirements: !ruby/object:Gem::Requirement
46
50
  requirements: