Changeset ac39a3b330cbf7c4b65ba907783364b63fb109b3

Show
Ignore:
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:
10 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    ra4a5b3b rac39a3b  
     12007-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 
    1102007-03-31  Dmitry Kim <dmitry.kim@gmail.com> 
    211 
     
    1322        encodings support), please use get_partial() or get_request() instead. 
    1423        * Utils: http_get() method has been removed (long obsoleted by 
    15         HttpUtil) 
     24        HttpUtil) 
    1625        * different plugins: modified to accomodate for HttpUtil changes. 
    1726 
  • data/rbot/plugins/bans.rb

    redd1cf7 rac39a3b  
    3333#   * add proper auth management 
    3434 
    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  
     35define_structure :OnJoinAction, :host, :action, :channel, :reason 
     36define_structure :BadWordAction, :regexp, :action, :channel, :timer, :reason 
     37define_structure :WhitelistEntry, :host, :channel 
    3938 
    4039class BansPlugin < Plugin 
  • data/rbot/plugins/games/quiz.rb

    ra7b2718 rac39a3b  
    2828 
    2929# Class for storing question/answer pairs 
    30 QuizBundle = Struct.new( "QuizBundle", :question, :answer ) 
     30define_structure :QuizBundle, :question, :answer 
    3131 
    3232# Class for storing player stats 
    33 PlayerStats = Struct.new( "PlayerStats", :score, :jokers, :jokers_time ) 
     33define_structure :PlayerStats, :score, :jokers, :jokers_time 
    3434# Why do we still need jokers_time? //Firetech 
    3535 
  • data/rbot/plugins/games/roulette.rb

    r7d549a6 rac39a3b  
    1 RouletteHistory = Struct.new("RouletteHistory", :games, :shots, :deaths, :misses, :wins) 
     1define_structure :RouletteHistory, :games, :shots, :deaths, :misses, :wins 
    22 
    33class RoulettePlugin < Plugin 
  • data/rbot/plugins/quotes.rb

    re1556de rac39a3b  
    11# GB: Ok, we *really* need to switch to db for this plugin too 
    22 
    3 Quote = Struct.new("Quote", :num, :date, :source, :quote) 
     3define_structure :Quote, :num, :date, :source, :quote 
    44 
    55class QuotePlugin < Plugin 
  • data/rbot/plugins/script.rb

    r42045b5 rac39a3b  
    1414# like normal rbot plugins.  
    1515 
    16  
    17 Command = Struct.new( "Command", :code, :nick, :created, :channel ) 
    18  
     16define_structure :Command, :code, :nick, :created, :channel 
    1917 
    2018class ScriptPlugin < Plugin 
  • data/rbot/plugins/seen.rb

    rd29df50 rac39a3b  
    1 Saw = Struct.new("Saw", :nick, :time, :type, :where, :message) 
     1define_structure :Saw, :nick, :time, :type, :where, :message 
    22 
    33class SeenPlugin < Plugin 
  • data/rbot/plugins/url.rb

    rbf03d9f rac39a3b  
    1 Url = Struct.new("Url", :channel, :nick, :time, :url, :info) 
     1define_structure :Url, :channel, :nick, :time, :url, :info 
    22 
    33class ::UrlLinkError < RuntimeError 
  • lib/rbot/core/utils/extends.rb

    rb455c02 rac39a3b  
    1313# Please note that global symbols have to be prefixed by :: because this plugin 
    1414# will be read into an anonymous module 
     15 
     16# Extensions to the Module class 
     17# 
     18class ::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 
     38end 
    1539 
    1640 
  • lib/rbot/core/utils/utils.rb

    ra9b32ea rac39a3b  
    547547    end 
    548548 
    549  
    550549  end 
    551550end