sideshowcoder / canned

Server to respond with fake API responses, by using a directory of files for finding out what to say!
213 stars 46 forks source link

Extract can methods #26

Closed mulderp closed 10 years ago

mulderp commented 10 years ago

This is a minor refactoring that possibly helps to improve the readabiity of the mapping files to resources.

Actually, I am still a bit confused about what mappings are possible:

If this is correct, maybe it would help to extract one more method: _canSingleFile or similar. Then, the main mapping function would become:

 fs.stat(httpObj.path + '/' + httpObj.dname, function (err, stats) {
      if (err) {  // file exsits
          that._canSingleFile(httpObj);
        })
      } else {
        if (stats.isDirectory()) {
          that._canDirectory(httpObj);
        } else {
          new Response('html', '', 500, httpObj.res).send();
        }
      }

And it would be clearer to me how it works. What do you think?

sideshowcoder commented 10 years ago

Nice extraction, just so you know what is possible https://github.com/sideshowcoder/canned#awesome-so-what-is-supported has this outlined, is there anything you are confused about there? I'd love to improve but don't know how currently, is the syntax unclear maybe?

mulderp commented 10 years ago

I used respondWith... now. Indeed describes better what the code does. Let me know what you think.

mulderp commented 10 years ago

yeah ! :)