ganesha 0.0.1.alpha → 0.0.2.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ganesha.gemspec +3 -1
- data/lib/ganesha.rb +23 -2
- data/lib/ganesha/entities/link.rb +29 -0
- data/lib/ganesha/repositories/links_in_memory.rb +35 -0
- data/lib/ganesha/repository.rb +13 -0
- data/lib/ganesha/use_cases/current_links.rb +15 -0
- data/lib/ganesha/use_cases/links_between.rb +22 -0
- data/lib/ganesha/use_cases/save_link.rb +26 -0
- data/lib/ganesha/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/use_cases/current_links_spec.rb +27 -0
- data/spec/use_cases/links_between_spec.rb +30 -0
- data/spec/use_cases/save_link_spec.rb +51 -0
- metadata +43 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af2575ba215fa37cc13e8ef1521e696e3404aebc
|
4
|
+
data.tar.gz: e25d312d6bef55e547d22b75c7f96e385616bdcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c907e9d835d7a14c1baf0039be5f0d8a71c5c69ff63eccf1db60c0a0ed258aab0b522d4dbaf52e58d05406f512eaa2269e72841b4f988bf91f906d4b1bf98c14
|
7
|
+
data.tar.gz: 983ab60285e3ac247c7b5c224c5e8252a9f97a524c8ea3dcbbbe6d83f1bae8c8ec04b908d6c97a2cf0c31fefeb0b67d0184b1b1d295dedb568fa4a43356e149d
|
data/ganesha.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["fabianobeselga@gmail.com"]
|
11
11
|
spec.summary = %q{ Remember and share your links with your team on a weekly basis. }
|
12
12
|
spec.description = spec.summary
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/bezelga/ganesha"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "timecop"
|
25
|
+
spec.add_development_dependency "pry"
|
24
26
|
end
|
data/lib/ganesha.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'ganesha/version'
|
2
|
+
require 'ganesha/entities/link'
|
3
|
+
require 'ganesha/repository'
|
4
|
+
require 'ganesha/repositories/links_in_memory'
|
5
|
+
require 'ganesha/use_cases/save_link'
|
6
|
+
require 'ganesha/use_cases/current_links'
|
7
|
+
require 'ganesha/use_cases/links_between'
|
8
|
+
#Dir[File.dirname(__FILE__) + "/ganesha/use_cases/**/*.rb"].each { |file| require file }
|
9
|
+
|
10
|
+
Repository.register :links, Ganesha::Repositories::LinksInMemory.new
|
2
11
|
|
3
12
|
module Ganesha
|
4
|
-
|
13
|
+
class << self
|
14
|
+
def save_link(args)
|
15
|
+
UseCases::SaveLink.new(args).save
|
16
|
+
end
|
17
|
+
|
18
|
+
def links_between(args)
|
19
|
+
UseCases::LinksBetween.new(args).links
|
20
|
+
end
|
21
|
+
|
22
|
+
def current_links
|
23
|
+
UseCases::CurrentLinks.new.links
|
24
|
+
end
|
25
|
+
end
|
5
26
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Ganesha
|
2
|
+
module Entities
|
3
|
+
class Link
|
4
|
+
attr_accessor :id
|
5
|
+
attr_reader :url, :title, :created_at
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
@url = args.fetch(:url, '')
|
9
|
+
@title = args.fetch(:title, '')
|
10
|
+
@created_at = args.fetch(:created_at) { Time.now }
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: tell which field is not present if invalid
|
14
|
+
def valid?
|
15
|
+
url_present? && title_present?
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def url_present?
|
21
|
+
url && !url.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def title_present?
|
25
|
+
title && !title.empty?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Ganesha
|
2
|
+
module Repositories
|
3
|
+
class LinksInMemory
|
4
|
+
attr_reader :links, :next_id
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@links = {}
|
8
|
+
@next_id = 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def all
|
12
|
+
links.values
|
13
|
+
end
|
14
|
+
|
15
|
+
def between(from, to)
|
16
|
+
range = from..to
|
17
|
+
|
18
|
+
all.select do |link|
|
19
|
+
range.cover? link.created_at.to_date
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def save(link)
|
24
|
+
link.id = next_id
|
25
|
+
links[next_id] = link
|
26
|
+
@next_id += 1
|
27
|
+
link
|
28
|
+
end
|
29
|
+
|
30
|
+
def count
|
31
|
+
links.length
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ganesha
|
2
|
+
module UseCases
|
3
|
+
class LinksBetween
|
4
|
+
attr_reader :from, :to
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@from = args.fetch(:from)
|
8
|
+
@to = args.fetch(:to)
|
9
|
+
end
|
10
|
+
|
11
|
+
def links
|
12
|
+
links_repo.between(from, to)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def links_repo
|
18
|
+
Repository.for(:links)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Ganesha
|
2
|
+
module UseCases
|
3
|
+
class SaveLink
|
4
|
+
attr_reader :args
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@args = args
|
8
|
+
end
|
9
|
+
|
10
|
+
def save
|
11
|
+
return false unless link.valid?
|
12
|
+
links_repo.save(link)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def link
|
18
|
+
Entities::Link.new(args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def links_repo
|
22
|
+
Repository.for(:links)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/ganesha/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
3
|
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
4
|
# loaded once.
|
5
|
+
require 'ganesha'
|
6
|
+
require 'pry'
|
5
7
|
#
|
6
8
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
9
|
RSpec.configure do |config|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timecop'
|
3
|
+
|
4
|
+
describe Ganesha::UseCases::CurrentLinks do
|
5
|
+
|
6
|
+
describe '#links' do
|
7
|
+
subject(:links) { described_class.new.links }
|
8
|
+
let(:links_repo) { Repository.for(:links) }
|
9
|
+
|
10
|
+
let(:today) { Date.new(2013, 2, 14) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
Timecop.freeze(today)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
Timecop.return
|
18
|
+
end
|
19
|
+
|
20
|
+
let!(:link1) { Ganesha.save_link({ url: 'www.something.com', title: 'Something', created_at: Date.new(2013, 2, 1) }) }
|
21
|
+
let!(:link2) { Ganesha.save_link({ url: 'www.something.com', title: 'Something', created_at: Date.new(2013, 2, 13) }) }
|
22
|
+
|
23
|
+
xit 'returns the current week links' do
|
24
|
+
should == [link2]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timecop'
|
3
|
+
|
4
|
+
describe Ganesha::UseCases::LinksBetween do
|
5
|
+
describe '#links' do
|
6
|
+
subject(:links) { described_class.new({ from: from, to: to }).links }
|
7
|
+
let(:links_repo) { Repository.for(:links) }
|
8
|
+
|
9
|
+
let(:today) { Date.new(2013, 2, 14) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
Timecop.freeze(today)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
Timecop.return
|
17
|
+
end
|
18
|
+
|
19
|
+
let!(:link1) { Ganesha.save_link({ url: 'www.something.com', title: 'Something', created_at: Date.new(2013, 2, 1) }) }
|
20
|
+
let!(:link2) { Ganesha.save_link({ url: 'www.something.com', title: 'Something', created_at: Date.new(2013, 2, 13) }) }
|
21
|
+
|
22
|
+
|
23
|
+
context 'fetching the current week' do
|
24
|
+
let(:from) { Date.new(2013, 2, 10) }
|
25
|
+
let(:to) { Date.new(2013, 2, 14) }
|
26
|
+
|
27
|
+
it { should == [link2] }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ganesha::UseCases::SaveLink do
|
4
|
+
|
5
|
+
describe '#save' do
|
6
|
+
subject(:save) { described_class.new({ url: url, title: title }).save }
|
7
|
+
|
8
|
+
let(:url) { 'https://github.com/bezelga/ganesha' }
|
9
|
+
let(:title) { 'Ganesha' }
|
10
|
+
let(:links_repo) { Repository.for(:links) }
|
11
|
+
|
12
|
+
context 'when all params are valid' do
|
13
|
+
it 'saves the link' do
|
14
|
+
expect { save }.to change { links_repo.count }.by(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: test using timecop or doleroean
|
18
|
+
its(:created_at) { should_not be_nil }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the url is blank' do
|
22
|
+
let(:url) { '' }
|
23
|
+
|
24
|
+
it 'does not save the link' do
|
25
|
+
expect { save }.to_not change { links_repo.count }
|
26
|
+
end
|
27
|
+
|
28
|
+
it { should be_false }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when the title is blank' do
|
32
|
+
let(:title) { '' }
|
33
|
+
|
34
|
+
it 'does not save the link' do
|
35
|
+
expect { save }.to_not change { links_repo.count }
|
36
|
+
end
|
37
|
+
|
38
|
+
it { should be_false }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when url is nil' do
|
42
|
+
let(:url) { nil }
|
43
|
+
|
44
|
+
it 'does not save the link' do
|
45
|
+
expect { save }.to_not change { links_repo.count }
|
46
|
+
end
|
47
|
+
|
48
|
+
it { should be_false }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ganesha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.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-02-
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: Remember and share your links with your team on a weekly basis.
|
56
84
|
email:
|
57
85
|
- fabianobeselga@gmail.com
|
@@ -67,9 +95,18 @@ files:
|
|
67
95
|
- Rakefile
|
68
96
|
- ganesha.gemspec
|
69
97
|
- lib/ganesha.rb
|
98
|
+
- lib/ganesha/entities/link.rb
|
99
|
+
- lib/ganesha/repositories/links_in_memory.rb
|
100
|
+
- lib/ganesha/repository.rb
|
101
|
+
- lib/ganesha/use_cases/current_links.rb
|
102
|
+
- lib/ganesha/use_cases/links_between.rb
|
103
|
+
- lib/ganesha/use_cases/save_link.rb
|
70
104
|
- lib/ganesha/version.rb
|
71
105
|
- spec/spec_helper.rb
|
72
|
-
|
106
|
+
- spec/use_cases/current_links_spec.rb
|
107
|
+
- spec/use_cases/links_between_spec.rb
|
108
|
+
- spec/use_cases/save_link_spec.rb
|
109
|
+
homepage: https://github.com/bezelga/ganesha
|
73
110
|
licenses:
|
74
111
|
- MIT
|
75
112
|
metadata: {}
|
@@ -95,3 +132,6 @@ specification_version: 4
|
|
95
132
|
summary: Remember and share your links with your team on a weekly basis.
|
96
133
|
test_files:
|
97
134
|
- spec/spec_helper.rb
|
135
|
+
- spec/use_cases/current_links_spec.rb
|
136
|
+
- spec/use_cases/links_between_spec.rb
|
137
|
+
- spec/use_cases/save_link_spec.rb
|