Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Commits on Jan 12, 2012
  1. Put things in their own files.

    authored
    We should try to stick to one class per file. Same
    with specs.
  2. Cleaned up the look of the code.

    authored
    Those comments were pretty bad; they just re-iterated what the
    code does, rather than why the code is doing it. We'll reintroduce
    comments in another commit, but first, let's just clean up the look
    and some minor spacing issues.
  3. using rspec's let feature to great effect.

    authored
    Two changes here: the first is to use an awesome feature of rspec: let.
    
    Basically, we can let rspec instantiate our object, which gets
    all of that typing of long class names out of the way. It also lets
    our tests focus on what's important, and ignore what isn't. Read the tests
    now: "When the ip is this, I expect the locator to do that."
    
    The second thing was breaking the last test into two. I wanted to do
    this as a separate step, but it didn't work until I made the change:
    you really had two assertions in that last one. It deserves its own
    test.
  4. removing outdated tests.

    authored
    Let's only keep the new tests, now that we're sure about them.
  5. introducing tests for the new class.

    authored
    I'm leaving the old tests in for now, to show that we're passing both.
    Since the tests are so similar, we can show that we have a high
    level of confidence that we're testing the same behavior, and
    get rid of the old tests.
  6. Getting rid of private by introducing new class.

    authored
    Your original code felt the tension of two responsibilities: you
    have your own processing to do, as well as processing from calling
    an external service. You can see it in the code: you split it up
    into two methods for a reason. However, you marked the second as
    private, because you didn't want to make that part of your external
    API.
    
    That's great, but testing private methods is difficult, as your tests
    show. You're testing the private method through the public one, which
    is better than some Object#send shennanigans to test it directly.
    However, we can do better!
    
    Instead, let's make a new object, and consider it private, for our
    own use. We can use that object to wrap the external API, which
    provides two benefits:
    
    1) clear respect of the SRP principle. One object for our stuff, one
    object for external processing.
    2) a seam to migrate to a different service in the future. We can implement
    and use a different external service object, and none of our code
    has to change.
    
    Because we're testing through the public methods, no changes in tests are required.
  7. From structured to OO style.

    authored
    The current style of the code is in a procedural style. "Here's a
    function, it's namespaced by my class." The standard idiom would
    have been to do this:
    
    ```
    module Geolocator
      extend self
    
      def ip_lookup
      <snip>
    end
    ```
    
    However, Ruby is OO, not procedural. Let's take advantage of that!
    Basically, you can construct an object with the arguments instead.
    So now, we construct a geolocator object with an IP address, and
    then ask it to look up the IP.
    
    Right now it might not seem like much, but imagine two or three
    operations on an object:
    
    ```
    Geolocator.ip_lookup("123.456.789.123")
    Geolocator.resolve_domain("123.456.789.123")
    Geolocator.valid_ip?("123.456.789.123")
    ```
    
    vs
    
    ```
    locator = Geolocator.new("123.456.789.123")
    locator.ip_lookup
    locator.resolve_domain
    locator.valid_ip?
    ```
    
    Much more DRY.
    
    There are also testing benefits to doing things this way: a bag
    of methods module is harder to test than an object.
  8. adding rake to gemspec

    authored
    It's a good idea to include _all_ the things you rely on in your
    gemspec. That includes rake. Since it's only used for development,
    I've added it as a development dependency.
  9. @thoughtpunch
Commits on Jan 11, 2012
  1. @jhsu

    rename to Geolocator

    jhsu authored
  2. @thoughtpunch

    added .gemtest

    thoughtpunch authored
  3. @thoughtpunch

    updating README

    thoughtpunch authored
  4. @thoughtpunch

    updated README

    thoughtpunch authored
  5. @thoughtpunch

    added sections to README

    thoughtpunch authored
  6. @thoughtpunch

    bumping to version 0.0.1

    thoughtpunch authored
  7. @thoughtpunch
  8. @thoughtpunch

    refactoring class methods

    thoughtpunch authored
  9. @thoughtpunch

    wrote first tests

    thoughtpunch authored
  10. @thoughtpunch

    updated readme

    thoughtpunch authored
  11. @thoughtpunch

    first commit

    thoughtpunch authored
Something went wrong with that request. Please try again.