This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tod.configure do |config| | |
config.repo = TasksRepository::ActiveRecord | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TasksRepository::ActiveRecord | |
def persist(task_entity) | |
task = Task.create({ title: task_entity.title }) | |
serialize task | |
end | |
def count | |
Task.count | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tod | |
module TasksRepository | |
class InMemory | |
def initialize | |
@tasks = {} | |
@id = 0 | |
end | |
def persist(task) | |
@id += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tod | |
module Entities | |
class Task | |
attr_accessor :id | |
attr_reader :title | |
def initialize(title: '') | |
@title = title | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tod | |
class << self | |
attr_accessor :repo | |
def configure | |
yield self | |
end | |
def repo | |
@repo ||= TasksRepository::InMemory.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tod.add_task('write about clean architecture') |
NewerOlder