NUBIC/ncs_navigator_core — pull request #74 by yipdw (2013-03-18 23:00:17+00:00)
Title: Clarify targets of response set prepopulators

Currently, to use a `ResponseSetPopulator`, you have to pass in a bunch of stuff:

```ruby
module NcsNavigator::Core::ResponseSetPopulator
class Base
def initialize(person, instrument, survey, options = {})
# ...
end
end
```

Note, however, that a response set is not among the initialization parameters.

This is odd, but it's also very inconvenient for https://code.bioinformatics.northwestern.edu/issues/issues/show/2744. As we plan to use prepopulators to generate contexts (and therefore lock contexts to response sets), the most natural expression for that task is something like this:

```ruby
rs = ResponseSet.find(...)
rs.prepopulate
rs.to_mustache
```

because it establishes a one-to-one relationship between the instrument context and its response set. However, in order to do that with the current API, you need to start reaching in a lot of places:

```ruby
class ResponseSet
def prepopulate
options = { :event => ?, :mode => ? }
rsp = ResponseSetPopulator::Base.new.try(person, instrument, survey, options)
rsp.process
end
end
```

In fact, the above code is _wrong_, because there's no guarantee that the prepopulators will actually populate the desired response set.

This PR introduces a new API that looks like this:

```ruby
class ResponseSet < ActiveRecord::Base
def prepopulate
populators_for(self).each(&:run)
end
end
```

where `populators_for` is

```ruby
def populators_for(response_set)
POPULATORS.select { |p| p.applies_to?(response_set) }.map { |p| p.new(response_set) }
end
```

This PR also adapts all existing response set prepopulators and their specs to use this new API. Changes to the internals of response set prepopulators was kept to a minimum.

@jdzak performed the vast majority of the porting work. He's told me that the ports are up-to-date with master. I've verified this to the best of my ability, but second opinions would be nice.