Changeset ac39a3b330cbf7c4b65ba907783364b63fb109b3
- Timestamp:
- 04/12/07 14:35:45 (3 years ago)
- Author:
- Giuseppe Bilotta <giuseppe.bilotta@…>
- Children:
- 5f58c780eea198c68e8b9528c9c07cca0f401257
- Parents:
- bf03d9f2b695772212abee81d405483c5c374633
- git-committer:
- Giuseppe Bilotta <giuseppe.bilotta@gmail.com> 1176374145 +0000
- Message:
-
Module\#define_structure method: define a new Struct only if doesn't exist already or if the attribute list changed
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
ra4a5b3b
|
rac39a3b
|
|
| | 1 | 2007-04-12 Giuseppe Bilotta <giuseppe.bilotta@gmail.com> |
| | 2 | |
| | 3 | * Basic class extensions: Module#define_structure() method. Syntax: |
| | 4 | define_structure :SomeName, :attr_a, :attr_b |
| | 5 | is equivalent to |
| | 6 | SomeName = Struct.new("SomeName", :attr_a, :attr_b) |
| | 7 | except that the new Struct is not created if it already exists and the |
| | 8 | attributes list is the same. |
| | 9 | |
| 1 | 10 | 2007-03-31 Dmitry Kim <dmitry.kim@gmail.com> |
| 2 | 11 | |
| … |
… |
|
| 13 | 22 | encodings support), please use get_partial() or get_request() instead. |
| 14 | 23 | * Utils: http_get() method has been removed (long obsoleted by |
| 15 | | HttpUtil) |
| | 24 | HttpUtil) |
| 16 | 25 | * different plugins: modified to accomodate for HttpUtil changes. |
| 17 | 26 | |
-
|
redd1cf7
|
rac39a3b
|
|
| 33 | 33 | # * add proper auth management |
| 34 | 34 | |
| 35 | | OnJoinAction = Struct.new("OnJoinAction", :host, :action, :channel, :reason) |
| 36 | | BadWordAction = Struct.new("BadWordAction", :regexp, :action, :channel, :timer, :reason) |
| 37 | | WhitelistEntry = Struct.new("WhitelistEntry", :host, :channel) |
| 38 | | |
| | 35 | define_structure :OnJoinAction, :host, :action, :channel, :reason |
| | 36 | define_structure :BadWordAction, :regexp, :action, :channel, :timer, :reason |
| | 37 | define_structure :WhitelistEntry, :host, :channel |
| 39 | 38 | |
| 40 | 39 | class BansPlugin < Plugin |
-
|
ra7b2718
|
rac39a3b
|
|
| 28 | 28 | |
| 29 | 29 | # Class for storing question/answer pairs |
| 30 | | QuizBundle = Struct.new( "QuizBundle", :question, :answer ) |
| | 30 | define_structure :QuizBundle, :question, :answer |
| 31 | 31 | |
| 32 | 32 | # Class for storing player stats |
| 33 | | PlayerStats = Struct.new( "PlayerStats", :score, :jokers, :jokers_time ) |
| | 33 | define_structure :PlayerStats, :score, :jokers, :jokers_time |
| 34 | 34 | # Why do we still need jokers_time? //Firetech |
| 35 | 35 | |
-
|
r7d549a6
|
rac39a3b
|
|
| 1 | | RouletteHistory = Struct.new("RouletteHistory", :games, :shots, :deaths, :misses, :wins) |
| | 1 | define_structure :RouletteHistory, :games, :shots, :deaths, :misses, :wins |
| 2 | 2 | |
| 3 | 3 | class RoulettePlugin < Plugin |
-
|
re1556de
|
rac39a3b
|
|
| 1 | 1 | # GB: Ok, we *really* need to switch to db for this plugin too |
| 2 | 2 | |
| 3 | | Quote = Struct.new("Quote", :num, :date, :source, :quote) |
| | 3 | define_structure :Quote, :num, :date, :source, :quote |
| 4 | 4 | |
| 5 | 5 | class QuotePlugin < Plugin |
-
|
r42045b5
|
rac39a3b
|
|
| 14 | 14 | # like normal rbot plugins. |
| 15 | 15 | |
| 16 | | |
| 17 | | Command = Struct.new( "Command", :code, :nick, :created, :channel ) |
| 18 | | |
| | 16 | define_structure :Command, :code, :nick, :created, :channel |
| 19 | 17 | |
| 20 | 18 | class ScriptPlugin < Plugin |
-
|
rd29df50
|
rac39a3b
|
|
| 1 | | Saw = Struct.new("Saw", :nick, :time, :type, :where, :message) |
| | 1 | define_structure :Saw, :nick, :time, :type, :where, :message |
| 2 | 2 | |
| 3 | 3 | class SeenPlugin < Plugin |
-
|
rbf03d9f
|
rac39a3b
|
|
| 1 | | Url = Struct.new("Url", :channel, :nick, :time, :url, :info) |
| | 1 | define_structure :Url, :channel, :nick, :time, :url, :info |
| 2 | 2 | |
| 3 | 3 | class ::UrlLinkError < RuntimeError |
-
|
rb455c02
|
rac39a3b
|
|
| 13 | 13 | # Please note that global symbols have to be prefixed by :: because this plugin |
| 14 | 14 | # will be read into an anonymous module |
| | 15 | |
| | 16 | # Extensions to the Module class |
| | 17 | # |
| | 18 | class ::Module |
| | 19 | |
| | 20 | # Many plugins define Struct objects to hold their data. On rescans, lots of |
| | 21 | # warnings are echoed because of the redefinitions. Using this method solves |
| | 22 | # the problem, by checking if the Struct already exists, and if it has the |
| | 23 | # same attributes |
| | 24 | # |
| | 25 | def define_structure(name, *members) |
| | 26 | sym = name.to_sym |
| | 27 | if Struct.const_defined?(sym) |
| | 28 | kl = Struct.const_get(sym) |
| | 29 | if kl.new.members.map { |member| member.intern } == members.map |
| | 30 | debug "Struct #{sym} previously defined, skipping" |
| | 31 | const_set(sym, kl) |
| | 32 | return |
| | 33 | end |
| | 34 | end |
| | 35 | debug "Defining struct #{sym} with members #{members.inspect}" |
| | 36 | const_set(sym, Struct.new(name.to_s, *members)) |
| | 37 | end |
| | 38 | end |
| 15 | 39 | |
| 16 | 40 | |
-