Class: Blur::Script
- Inherits:
-
Module
- Object
- Module
- Blur::Script
- Includes:
- Logging
- Defined in:
- library/blur/script.rb,
library/blur/script/cache.rb,
library/blur/script/messageparsing.rb
Overview
add examples in the documentation
The Script class is used for encapsulating dynamically loaded ruby scripts.
The #Script method is then used to shape the DSL-language to make writing Blur scripts a breeze.
Defined Under Namespace
Modules: MessageParsing Classes: Cache
Constant Summary
- Emissions =
[:connection_ready, :topic_change, :user_rename, :message, :private_message, :user_entered, :user_left, :user_quit, :user_kicked, :topic, :user_mode, :channel_mode]
Instance Attribute Summary (collapse)
-
- (Object) __author
The author of the script.
-
- (Network::Client) __client
Can be used inside the script to act with the client itself.
-
- (Array) __emissions
A list of handled emissions.
-
- (Object) __name
The name of the script.
-
- (Object) __path
The path in which the script remains.
-
- (Object) __version
The version of the script.
Instance Method Summary (collapse)
-
- (Object) cache
Get the cache, if none, instantiate a new cache.
-
- (Boolean) evaluated?
Check to see if the script has been evaluated.
-
- (Script) initialize(path)
constructor
Instantiates a script and evaluates the contents which remain in path.
-
- (Object) inspect
Convert it to a debug-friendly format.
-
- (Script) script(name)
Access another script with name name.
-
- (Object) Script(name, version = [1,0], author = nil, &block)
Make it a DSL-way of writing a script.
-
- (Object) unload!
Unload the script and save the cache, if present.
Constructor Details
- (Script) initialize(path)
Instantiates a script and evaluates the contents which remain in path.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'library/blur/script.rb', line 36 def initialize path @__path = path @__evaluated = false @__emissions = [] if evaluate and @__evaluated cache.load if Cache.exists? @__name Emissions.each do |emission| @__emissions.push emission if respond_to? emission end __send__ :loaded if respond_to? :loaded end end |
Instance Attribute Details
- (Object) __author
The author of the script.
21 22 23 |
# File 'library/blur/script.rb', line 21 def @__author end |
- (Network::Client) __client
Can be used inside the script to act with the client itself.
28 29 30 |
# File 'library/blur/script.rb', line 28 def __client @__client end |
- (Array) __emissions
A list of handled emissions.
30 31 32 |
# File 'library/blur/script.rb', line 30 def __emissions @__emissions end |
- (Object) __name
The name of the script.
19 20 21 |
# File 'library/blur/script.rb', line 19 def __name @__name end |
- (Object) __path
The path in which the script remains.
25 26 27 |
# File 'library/blur/script.rb', line 25 def __path @__path end |
- (Object) __version
The version of the script.
23 24 25 |
# File 'library/blur/script.rb', line 23 def __version @__version end |
Instance Method Details
- (Object) cache
Get the cache, if none, instantiate a new cache.
86 87 88 |
# File 'library/blur/script.rb', line 86 def cache @__cache ||= Cache.new self end |
- (Boolean) evaluated?
Check to see if the script has been evaluated.
33 |
# File 'library/blur/script.rb', line 33 def evaluated?; @__evaluated end |
- (Object) inspect
Convert it to a debug-friendly format.
91 92 93 |
# File 'library/blur/script.rb', line 91 def inspect File.basename @__path end |
- (Script) script(name)
Access another script with name name.
81 82 83 |
# File 'library/blur/script.rb', line 81 def script name @__client.scripts.find { |script| script.__name == name } end |
- (Object) Script(name, version = [1,0], author = nil, &block)
Make it a DSL-way of writing a script.
60 61 62 63 64 65 66 67 68 |
# File 'library/blur/script.rb', line 60 def Script name, version = [1,0], = nil, &block @__name = name @__author = @__version = version instance_eval &block true end |
- (Object) unload!
Unload the script and save the cache, if present.
71 72 73 74 75 76 |
# File 'library/blur/script.rb', line 71 def unload! cache.save if @__cache __send__ :unloaded if respond_to? :unloaded @__cache = nil end |