Changeset 227

Show
Ignore:
Timestamp:
06/11/05 19:34:39 (3 years ago)
Author:
ged
Message:

- Moved #checkForHashArgs out of GameObject? into ArgCheckFunctions?.

Location:
trunk/lib/fm
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/fm/gameobject.rb

    r226 r227  
    156156 
    157157    # This must come after the declaration of the contributors method above. 
    158     contributors :ged 
     158    contributors :ged, :stillflame 
    159159 
    160160    ### Initialize a new FaerieMUD::GameObject. Arguments in the  
     
    339339    end 
    340340 
    341  
    342     ####### 
    343     private 
    344     ####### 
    345  
    346     ################################################################# 
    347     ### U T I L I T Y   F U N C T I O N S 
    348     ################################################################# 
    349  
    350     ### Check to be sure the specified +args+ object is a Hash and contains 
    351     ### the given +keys+. Each key in +keys+ can be either a Symbol, a 
    352     ### String, or an Array of either. 
    353     def checkForHashArgs( args, *keys ) 
    354         unless args.is_a?( Hash ) 
    355             raise TypeError,  
    356                 "Arguments are not in Hash form.", 
    357                 caller(1).find_all {|frame| /#{__FILE__}/ !~ frame} 
    358         end 
    359  
    360         unless keys.empty? 
    361             nicetrace = caller( 1 ).delete_if {|frame| 
    362                 /#{__FILE__}:\d+:in/i =~ frame 
    363             } 
    364             keys.each {|required| 
    365                 case required 
    366                 when Symbol 
    367                     raise ArgumentError, 
    368                         "Missing required argument :#{required}", 
    369                         nicetrace unless 
    370                         args.key?( required ) 
    371                 when String 
    372                     raise ArgumentError, 
    373                         "Missing required argument :#{required}", 
    374                         nicetrace unless 
    375                         args.key?( required.intern ) 
    376                 when Array 
    377                     raise ArgumentError, 
    378                         "Missing required argument :#{requiredKey}", 
    379                         nicetrace unless 
    380                         required. 
    381                         collect {|ak| ak.to_s.intern }. 
    382                         find {|ak| args.keys.include?(ak) } 
    383                 end 
    384  
    385             } 
    386         end 
    387  
    388         return true 
    389     end 
    390  
    391  
    392341end # class FaerieMUD::GameObject 
    393342 
  • trunk/lib/fm/mixins.rb

    r205 r227  
    55# Currently contains the following modules: 
    66# 
     7# [<tt>FaerieMUD::ArgCheckFunctions</tt>] 
     8#   Functions for checking arguments for types, signatures, and hash members. 
     9#  
    710# [<tt>FaerieMUD::Propertied</tt>] 
    811#   Adds the ability to interact with FaerieMUD::Property objects to including 
     
    5356 
    5457require 'fm/exceptions' 
    55  
    5658 
    5759module FaerieMUD 
     
    181183        end 
    182184 
     185 
     186        ### Check to be sure the specified +args+ object is a Hash and contains 
     187        ### the given +keys+. Each key in +keys+ can be either a Symbol, a 
     188        ### String, or an Array of either. 
     189        def checkForHashArgs( args, *keys ) 
     190            unless args.is_a?( Hash ) 
     191                raise TypeError,  
     192                    "Arguments are not in Hash form.", 
     193                    caller(1).find_all {|frame| /#{__FILE__}/ !~ frame} 
     194            end 
     195 
     196            unless keys.empty? 
     197                nicetrace = caller( 1 ).delete_if {|frame| 
     198                    /#{__FILE__}:\d+:in/i =~ frame 
     199                } 
     200                keys.each {|required| 
     201                    case required 
     202                    when Symbol 
     203                        raise ArgumentError, 
     204                            "Missing required argument :#{required}", 
     205                            nicetrace unless 
     206                            args.key?( required ) 
     207                    when String 
     208                        raise ArgumentError, 
     209                            "Missing required argument :#{required}", 
     210                            nicetrace unless 
     211                            args.key?( required.intern ) 
     212                    when Array 
     213                        raise ArgumentError, 
     214                            "Missing required argument :#{requiredKey}", 
     215                            nicetrace unless 
     216                            required. 
     217                            collect {|ak| ak.to_s.intern }. 
     218                            find {|ak| args.keys.include?(ak) } 
     219                    end 
     220 
     221                } 
     222            end 
     223 
     224            return true 
     225        end 
     226 
    183227    end # module ArgCheckFunctions 
    184228