bulldoggy 0.0.2.alpha → 0.0.3.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c2691c7f1227ffaa6b5978e82b8baaa1061caae
4
- data.tar.gz: bb59d4d4ed88ec37362f45115cd1029f315acdb7
3
+ metadata.gz: 6d8a4206ac727653745dcbe517a26fdb0ab714a4
4
+ data.tar.gz: 0b015676023a0aaf41bac6e3280058238d2db3fe
5
5
  SHA512:
6
- metadata.gz: 977d094ea3955e831003a9de3de8419074f5b91ff301e14112919d312d3f0b85abb07d897865b413e6bd560e92c303a51eadf45b54bc06f8942a1d0f492acbde
7
- data.tar.gz: 80db4f74a3a88477e1385e3a41cc5105c0b295efe2f9b11fc340d548480cc1831d226875ca05265b1a2954ed95bb846b4cd48944b3fd2b2fb42587a38cd3b2bd
6
+ metadata.gz: 64b2e1c2cee54cf378ea5bb331eb97e2e39ba5670ca623dd5f4e4c92ecb73e52ede8c0150c0515832388e3aec7ed191203c538986d3f6db8148ffc6695fec1a9
7
+ data.tar.gz: 2445bfea6850c94a4a408dac7fe0a2b7492bb662a6553da3ce7e284563fc70173daf37e6edcd43e5ffc28af1cf210e5abf100dd4c1978bb7e81809a696f0073e
@@ -0,0 +1,11 @@
1
+ module Bulldoggy
2
+ module Entities
3
+ class Task
4
+ attr_accessor :id, :description
5
+
6
+ def initialize(description)
7
+ @description = description
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ module Bulldoggy
2
+ module Repositories
3
+ module InMemory
4
+ class Tasks
5
+ def initialize
6
+ @tasks = {}
7
+ @next_id = 1
8
+ end
9
+
10
+ def save(task)
11
+ task.id = @next_id
12
+ @tasks[@next_id] = task
13
+ @next_id += 1
14
+ task
15
+ end
16
+
17
+ def all
18
+ @tasks
19
+ end
20
+
21
+ def delete_all
22
+ @tasks = {}
23
+ @next_id = 1
24
+ end
25
+
26
+ def first
27
+ first_key = @tasks.keys.sort.first
28
+ @tasks[first_key]
29
+ end
30
+
31
+ def last
32
+ last_key = @tasks.keys.sort.last
33
+ @tasks[last_key]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,5 @@
1
+ require 'bulldoggy/repositories/in_memory/tasks'
2
+
1
3
  module Bulldoggy
2
4
  class Repository
3
5
  def self.register(type, repo)
@@ -0,0 +1,19 @@
1
+ module Bulldoggy
2
+ module UseCases
3
+ class TaskAdder
4
+ def add(description)
5
+ task_repo.save new_task(description)
6
+ end
7
+
8
+ private
9
+
10
+ def new_task(description)
11
+ Entities::Task.new(description)
12
+ end
13
+
14
+ def task_repo
15
+ Repository.for(:task)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module Bulldoggy
2
+ module UseCases
3
+ class TasksFetcher
4
+ def fetch
5
+ Bulldoggy::Repository.for(:task).all.map do |id, task|
6
+ # IMPROVE: create a TaskSerializer to do this job
7
+ { id: id, description: task.description }
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Bulldoggy
2
- VERSION = "0.0.2.alpha"
2
+ VERSION = "0.0.3.alpha"
3
3
  end
data/lib/bulldoggy.rb CHANGED
@@ -1,12 +1,23 @@
1
1
  require "bulldoggy/version"
2
2
 
3
- require 'bulldoggy/use_cases/list_creator'
4
- require 'bulldoggy/entities/list'
3
+ require 'bulldoggy/entities/task'
5
4
  require 'bulldoggy/repository'
6
- require 'bulldoggy/repositories/in_memory/lists'
5
+
6
+ require 'bulldoggy/use_cases/task_adder'
7
+ require 'bulldoggy/use_cases/tasks_fetcher'
8
+
9
+ Bulldoggy::Repository.register :task, Bulldoggy::Repositories::InMemory::Tasks.new
7
10
 
8
11
  module Bulldoggy
9
- # Your code goes here...
12
+ class << self
13
+ # TODO: test me
14
+ def add_task(description)
15
+ UseCases::TaskAdder.new.add(description)
16
+ end
17
+
18
+ def fetch
19
+ UseCases::TasksFetcher.new.fetch
20
+ end
21
+ end
10
22
  end
11
23
 
12
- Bulldoggy::Repository.register :list, Bulldoggy::Repositories::InMemory::Lists.new
File without changes
data/spec/spec_helper.rb CHANGED
@@ -17,4 +17,8 @@ RSpec.configure do |config|
17
17
  # the seed, which is printed after each run.
18
18
  # --seed 1234
19
19
  config.order = 'random'
20
+
21
+ config.before do
22
+ Bulldoggy::Repository.for(:task).delete_all
23
+ end
20
24
  end
@@ -1,18 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- #describe TaskAdder do
4
- #subject(:adder) { described_class }
3
+ describe Bulldoggy::UseCases::TaskAdder do
4
+ subject(:adder) { described_class.new }
5
5
 
6
- #describe '.add' do
7
- #subject(:add) { adder.add(description, list_id) }
6
+ describe '.add' do
7
+ subject(:add) { adder.add(description) }
8
8
 
9
- #let(:description) { 'Create an app with clean architecture' }
10
- #let(:id) { 1 }
9
+ let(:task_repo) { Bulldoggy::Repository.for(:task) }
10
+ let(:description) { 'Create an app with clean architecture' }
11
11
 
12
- #context 'when the list exists' do
13
- #xit 'adds a task to the list' do
14
- #add.should be_true
15
- #end
16
- #end
17
- #end
18
- #end
12
+ it 'adds the task' do
13
+ expect { add }.to change { task_repo.all.size }.by(1)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module Bulldoggy
4
+ module UseCases
5
+ describe TasksFetcher do
6
+ subject(:fetcher) { described_class.new }
7
+
8
+ describe '#fetch' do
9
+ subject(:fetch) { fetcher.fetch }
10
+
11
+ let(:task_repo) { Repository.for(:task) }
12
+
13
+ context 'when there are no tasks yet' do
14
+ it { should == [] }
15
+ end
16
+
17
+ context 'when there are 2 tasks' do
18
+ before do
19
+ 2.times do |n|
20
+ Bulldoggy.add_task("task##{n}")
21
+ end
22
+ end
23
+
24
+ let(:task1) { { id: 1, description: 'task#0' } }
25
+ let(:task2) { { id: 2, description: 'task#1' } }
26
+
27
+ it { should == [task1, task2] }
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulldoggy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.alpha
4
+ version: 0.0.3.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabiano B.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-27 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,16 +68,16 @@ files:
68
68
  - Rakefile
69
69
  - bulldoggy.gemspec
70
70
  - lib/bulldoggy.rb
71
- - lib/bulldoggy/entities/list.rb
72
- - lib/bulldoggy/repositories/in_memory/lists.rb
71
+ - lib/bulldoggy/entities/task.rb
72
+ - lib/bulldoggy/repositories/in_memory/tasks.rb
73
73
  - lib/bulldoggy/repository.rb
74
- - lib/bulldoggy/use_cases/list_creator.rb
74
+ - lib/bulldoggy/use_cases/task_adder.rb
75
+ - lib/bulldoggy/use_cases/tasks_fetcher.rb
75
76
  - lib/bulldoggy/version.rb
76
- - spec/entities/list_spec.rb
77
- - spec/repositories/in_memory/lists_spec.rb
77
+ - spec/repositories/in_memory/tasks_spec.rb
78
78
  - spec/spec_helper.rb
79
- - spec/use_cases/list_creator_spec.rb
80
79
  - spec/use_cases/task_adder_spec.rb
80
+ - spec/use_cases/tasks_fetcher_spec.rb
81
81
  homepage: ''
82
82
  licenses:
83
83
  - MIT
@@ -103,8 +103,7 @@ signing_key:
103
103
  specification_version: 4
104
104
  summary: Bulldoggy is a to-do list app inspired by Uncle Bob's Clean Architecture
105
105
  test_files:
106
- - spec/entities/list_spec.rb
107
- - spec/repositories/in_memory/lists_spec.rb
106
+ - spec/repositories/in_memory/tasks_spec.rb
108
107
  - spec/spec_helper.rb
109
- - spec/use_cases/list_creator_spec.rb
110
108
  - spec/use_cases/task_adder_spec.rb
109
+ - spec/use_cases/tasks_fetcher_spec.rb
@@ -1,10 +0,0 @@
1
- module Bulldoggy
2
- module Entities
3
- class List
4
- attr_accessor :name, :id
5
-
6
- def initialize(name)
7
- end
8
- end
9
- end
10
- end
@@ -1,33 +0,0 @@
1
- module Bulldoggy
2
- module Repositories
3
- module InMemory
4
- class Lists
5
- def initialize
6
- @lists = {}
7
- @next_id = 1
8
- end
9
-
10
- def save(list)
11
- list.id = @next_id
12
- @lists[@next_id] = list
13
- @next_id += 1
14
- list
15
- end
16
-
17
- def all
18
- @lists
19
- end
20
-
21
- def first
22
- first_key = @lists.keys.sort.first
23
- @lists[first_key]
24
- end
25
-
26
- def last
27
- last_key = @lists.keys.sort.last
28
- @lists[last_key]
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,29 +0,0 @@
1
- module Bulldoggy
2
- module UseCases
3
- class ListCreator
4
- def self.create(name)
5
- params = { name: name }
6
- new(params).create
7
- end
8
-
9
- def initialize(params)
10
- @params = params
11
- end
12
-
13
- def create
14
- saved_list = list_repo.save(list)
15
- saved_list.id
16
- end
17
-
18
- private
19
-
20
- def list
21
- Bulldoggy::Entities::List.new(@params[:name])
22
- end
23
-
24
- def list_repo
25
- Bulldoggy::Repository.for(:list)
26
- end
27
- end
28
- end
29
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bulldoggy::Entities::List do
4
- subject(:list) { described_class }
5
-
6
- describe 'instantiating a new list' do
7
- let(:name) { 'my awesome list name' }
8
-
9
- it 'instantiates a new list with a name' do
10
- list.new(name).should be_kind_of(list)
11
- end
12
- end
13
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bulldoggy::Repositories::InMemory::Lists do
4
- subject(:lists) { described_class.new }
5
-
6
- describe '#save' do
7
- let(:list) { Bulldoggy::Entities::List.new('hello world list') }
8
-
9
- it 'saves the list' do
10
- lists.save(list)
11
- expect { lists.save(list) }.to change { lists.all.size }.by(1)
12
- end
13
- end
14
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bulldoggy::UseCases::ListCreator do
4
- subject(:creator) { described_class }
5
-
6
- describe '.create' do
7
- subject(:create) { creator.create(name) }
8
-
9
- let(:name) { 'Learning Clean Architecture' }
10
- let(:list_repo) { Bulldoggy::Repository.for(:list) }
11
-
12
- it 'creates a list' do
13
- expect { create }.to change { list_repo.all.size }.by(1)
14
- end
15
-
16
- it 'responds the list id' do
17
- create.should == list_repo.all.size
18
- end
19
- end
20
- end