watson-ruby icon indicating copy to clipboard operation
watson-ruby copied to clipboard

gsub uses (.?)+ to grab anything after lib (optional), better regex? [lib/watson/config.rb]

Open nhmood opened this issue 11 years ago • 0 comments

filename : lib/watson/config.rb line # : 178 tag : review md5 : 93235816f8f628bd2b66ab6a860292dc

        # [review] - gsub uses (.?)+ to grab anything after lib (optional), better regex? 
        _full_path = __dir__.gsub(/\/lib(.?)+/, '') + "/" + "assets/defaultConf"
        debug_print "Full path to defaultConf (in gem): #{ _full_path }\n"

        # Check to make sure we can access the default file
        if !Watson::FS.check_file(_full_path)
            print "Unable to open #{ _full_path }\n"
            print "Cannot create default, exiting...\n"
            return false
        else
            # Open default config file in read mode and read into temp
            _input = File.open(_full_path, 'r')
            _default = _input.read
                # Open rc file in current directory in write mode and write default
            _output = File.open(@rc_file, 'w')
            _output.write(_default)

nhmood avatar Nov 21 '13 16:11 nhmood