In this article, DHH uses this example:
def publish!
self.update published_at: Time.now
endsaying DI folks would shiver at hard-coding Time.now
and that they would inject a clock or something to more easily test it.
| # in importer/logging.py | |
| import logging as log | |
| log.basicConfig(filename='importer.log', level=log.WARNING, format='%(message)s') | |
| # everywhere else: | |
| from importer.logging import log | |
| log.warning('used warning so i could look at the log without clutter from other projects') |
| def validate_token(secret, auth_token): | |
| # do the token check logic... (using settings.PARTNER_ID) | |
| def validate_token_from_yola(auth_token): | |
| yola = Yola() | |
| partner = yola.get_partner(settings.PARTNER_ID) | |
| validate_token(partner['shared_secret_key'], auth_token) |
| Can you describe some of the APIs you've worked on / built? | |
| - why did you make the choices you did? | |
| - how is it tested? | |
| If you had multiple legacy services that you wanted to combine into one new service, can you describe at a high-level how you'd do that? |
In this article, DHH uses this example:
def publish!
self.update published_at: Time.now
endsaying DI folks would shiver at hard-coding Time.now
and that they would inject a clock or something to more easily test it.
| # dumb example object with no dependencies: | |
| class Printer(object): | |
| def println(self, message): | |
| print message | |
| # dumb example object with dependencies: | |
| class Greeter(object): | |
| # can't use it without deciding on a printer |
| def write(msg): | |
| print msg | |
| class Plugins(object): | |
| plugins = { | |
| 'writer': write, | |
| } | |
| @classmethod | |
| def register(cls, name, plugin): |
| require "liquid" | |
| require "school/great_lesson/page_controller" | |
| require "school/great_lesson/page_repository" | |
| require "school/great_lesson/page_view" | |
| require "school/great_lesson/page_template" | |
| require "school/great_lesson/page_file_db" | |
| require "school/great_lesson/paginator" | |
| require "school/great_lesson/locates_pages_file" | |
| require "school/great_lesson/locates_page_template" |
| nav = SiteNavigation(site) | |
| nav.as_dict() | |
| nav = SiteNavigation.for_site_id(site_id) | |
| nav.as_dict() |
| # If this is the interface: | |
| SiteNavigation(site).as_dict() | |
| # that means we have to have a site object to build a site nav object. | |
| # That's fine within the Site object. | |
| # My point was that if (someday in the future) we need to build a nav object but we only have a site id, | |
| # instead of doing this: |
| class Site(models.model): | |
| # ... | |
| def get_navigation(self): | |
| return SiteNavigation(self.pages).as_dict() | |
| class SiteNavigation(object): | |
| # ... |