Skip to content

Instantly share code, notes, and snippets.

Tod.add_task('write about clean architecture')
require 'spec_helper'
describe Tod do
describe '.add_task' do
let(:repo) { Tod.repo }
it 'adds a new task' do
expect { Tod.add_task('speak @ Guru-SP') }.
to change{ repo.count }.by(1)
end
module Tod
class << self
attr_accessor :repo
def configure
yield self
end
def repo
@repo ||= TasksRepository::InMemory.new
module Tod
module UseCases
class AddTask
def self.add(title)
task = Entities::Task.new(title: title)
if task.valid?
Tod.repo.persist(task)
else
false
module Tod
module Entities
class Task
attr_accessor :id
attr_reader :title
def initialize(title: '')
@title = title
end
module Tod
module TasksRepository
class InMemory
def initialize
@tasks = {}
@id = 0
end
def persist(task)
@id += 1
class TasksRepository::ActiveRecord
def persist(task_entity)
task = Task.create({ title: task_entity.title })
serialize task
end
def count
Task.count
end
Tod.configure do |config|
config.repo = TasksRepository::ActiveRecord
end
@bezelga
bezelga / higlight.md
Last active August 29, 2015 14:15
Highlight code for keynote

highlight --font-size 20 --font Inconsolata --style fine_blue -W -J 140 --src-lang ruby -O rtf highlight.rb | pbcopy

@bezelga
bezelga / docker-machine-use-nfs.sh
Last active September 3, 2015 01:26 — forked from olalonde/docker-machine-use-nfs.sh
Use NFS instead of vboxsf in Docker Machine
#!/bin/bash
#
# This script will mount /Users in the boot2docker VM using NFS (instead of the
# default vboxsf). It's probably not a good idea to run it while there are
# Docker containers running in boot2docker.
#
# Usage: sudo ./boot2docker-use-nfs.sh
#