blur 1.6.2.pre → 1.7.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/library/blur.rb CHANGED
@@ -16,6 +16,7 @@ require 'blur/encryption'
16
16
  require 'blur/enhancements'
17
17
  require 'blur/script/cache'
18
18
  require 'blur/network/user'
19
+ require 'blur/script/fantasy'
19
20
  require 'blur/network/channel'
20
21
  require 'blur/network/command'
21
22
  require 'blur/network/connection'
@@ -27,7 +28,7 @@ require 'blur/script/messageparsing'
27
28
  # It can be by handlers, scripts, communications, and what have you.
28
29
  module Blur
29
30
  # The major and minor version-values of Blur.
30
- Version = "1.6.2.pre"
31
+ Version = "1.7.0"
31
32
 
32
33
  # Instantiates a client with given options and then makes the client instance
33
34
  # evaluate the given block to form a DSL.
@@ -46,6 +46,7 @@ module Blur
46
46
  end
47
47
 
48
48
  __send__ :loaded if respond_to? :loaded
49
+ __send__ :module_init if respond_to? :module_init
49
50
  end
50
51
  end
51
52
 
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ module Blur
4
+ class Script < Module
5
+ # The +Fantasy+ module is a module that gives the ability to turn a
6
+ # script into a DSL-like framework.
7
+ #
8
+ # What it does is automatically test to see if a message starts with a
9
+ # trigger, and then, if so, it sends the command-part of the message to
10
+ # the script object itself.
11
+ #
12
+ # This way, the plugin-writer doesn't need to have repetetive code like
13
+ # that in every script.
14
+ #
15
+ # @example
16
+ # Script :example do
17
+ # include Fantasy
18
+ #
19
+ # def command_test user, channel, message
20
+ # channel.say "I hear you."
21
+ # end
22
+ # end
23
+ #
24
+ # # And if a user were to send the message ".test my method", it would
25
+ # # trigger the #command_test method with the following arguments
26
+ # #
27
+ # # user => #<Blur::Network::User … >
28
+ # # channel => #<Blur::Network::Channel … >
29
+ # # message => ".test my method"
30
+ module Fantasy
31
+ # The prefix that turns it into a possible command.
32
+ MessageTrigger = "."
33
+
34
+ # Extend +klass+ with self.
35
+ def self.included klass
36
+ klass.extend self
37
+ end
38
+
39
+ # Called when a script has been loaded, for use in modules extending
40
+ # the script.
41
+ def module_init
42
+ @__fantasy_triggers = []
43
+
44
+ public_methods.grep(/^command_/).each do |trigger|
45
+ @__fantasy_triggers << trigger.to_s[8..-1]
46
+ end
47
+ end
48
+
49
+ # Handle all calls to the scripts +message+ method, check to see if
50
+ # the message containts a valid command, serialize it and pass it to
51
+ # the script as command_name with the parameters +user+, +channel+
52
+ # and +message+.
53
+ def message user, channel, line
54
+ return unless line.start_with? MessageTrigger
55
+
56
+ command, args = line.split $;, 2
57
+ trigger = serialize command
58
+
59
+ if @__fantasy_triggers.include? trigger
60
+ __send__ :"command_#{trigger}", user, channel, args
61
+ end
62
+ end
63
+
64
+ protected
65
+
66
+ # Strip all non-word characters from the input command.
67
+ def serialize name
68
+ name.gsub /\W/, '' if name
69
+ end
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blur
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2.pre
5
- prerelease: 6
4
+ version: 1.7.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mikkel Kroman
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-19 00:00:00.000000000 Z
12
+ date: 2012-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: majic
16
- requirement: &19385580 !ruby/object:Gem::Requirement
16
+ requirement: &10805240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19385580
24
+ version_requirements: *10805240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: crypt19
27
- requirement: &19401480 !ruby/object:Gem::Requirement
27
+ requirement: &10804700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19401480
35
+ version_requirements: *10804700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: eventmachine
38
- requirement: &19401020 !ruby/object:Gem::Requirement
38
+ requirement: &10804040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>'
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0.12'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *19401020
46
+ version_requirements: *10804040
47
47
  description: ! ' An event-driven IRC-framework in and for Ruby. Is extensible and
48
48
  supports script with (re)loading functionality during runtime.
49
49
 
@@ -53,21 +53,22 @@ executables: []
53
53
  extensions: []
54
54
  extra_rdoc_files: []
55
55
  files:
56
- - library/blur.rb
57
56
  - library/blur/client.rb
58
- - library/blur/encryption.rb
59
- - library/blur/encryption/base64.rb
60
- - library/blur/encryption/fish.rb
61
- - library/blur/enhancements.rb
62
- - library/blur/handling.rb
63
57
  - library/blur/network.rb
58
+ - library/blur/encryption/fish.rb
59
+ - library/blur/encryption/base64.rb
60
+ - library/blur/encryption.rb
61
+ - library/blur/script/fantasy.rb
62
+ - library/blur/script/cache.rb
63
+ - library/blur/script/messageparsing.rb
64
64
  - library/blur/network/channel.rb
65
65
  - library/blur/network/command.rb
66
- - library/blur/network/connection.rb
67
66
  - library/blur/network/user.rb
67
+ - library/blur/network/connection.rb
68
68
  - library/blur/script.rb
69
- - library/blur/script/cache.rb
70
- - library/blur/script/messageparsing.rb
69
+ - library/blur/enhancements.rb
70
+ - library/blur/handling.rb
71
+ - library/blur.rb
71
72
  homepage: https://github.com/mkroman/blur
72
73
  licenses:
73
74
  - ISC
@@ -84,12 +85,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
85
  required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  none: false
86
87
  requirements:
87
- - - ! '>'
88
+ - - ! '>='
88
89
  - !ruby/object:Gem::Version
89
- version: 1.3.1
90
+ version: '0'
90
91
  requirements: []
91
92
  rubyforge_project:
92
- rubygems_version: 1.8.10
93
+ rubygems_version: 1.8.11
93
94
  signing_key:
94
95
  specification_version: 3
95
96
  summary: An event-driven IRC-framework for Ruby.