rddd 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +3 -1
- data/README.md +8 -2
- data/Rakefile +5 -0
- data/lib/rddd.rb +5 -5
- data/lib/rddd/aggregates/entity.rb +75 -0
- data/lib/rddd/aggregates/finders.rb +23 -0
- data/lib/rddd/aggregates/repositories/base.rb +20 -0
- data/lib/rddd/aggregates/repositories/factory.rb +33 -0
- data/lib/rddd/aggregates/root.rb +25 -0
- data/lib/rddd/configuration.rb +1 -9
- data/lib/rddd/{service.rb → services/service.rb} +11 -9
- data/lib/rddd/{service_bus.rb → services/service_bus.rb} +23 -20
- data/lib/rddd/services/service_factory.rb +23 -0
- data/lib/rddd/version.rb +1 -1
- data/lib/rddd/views/cache.rb +24 -0
- data/lib/rddd/views/cacheable.rb +50 -0
- data/lib/rddd/views/view.rb +38 -0
- data/spec/integration_spec.rb +9 -9
- data/spec/lib/aggregates/entity_spec.rb +17 -0
- data/spec/lib/{aggregate_root_spec.rb → aggregates/root_spec.rb} +7 -7
- data/spec/lib/repositories/repository_factory_spec.rb +49 -0
- data/spec/lib/repositories/repository_spec.rb +30 -0
- data/spec/lib/{service_bus_spec.rb → services/service_bus_spec.rb} +6 -6
- data/spec/lib/services/service_factory_spec.rb +61 -0
- data/spec/lib/services/service_spec.rb +31 -0
- data/spec/lib/views/integration_spec.rb +153 -0
- metadata +29 -24
- data/lib/rddd/aggregate_root.rb +0 -17
- data/lib/rddd/aggregate_root_finders.rb +0 -21
- data/lib/rddd/entity.rb +0 -11
- data/lib/rddd/repository.rb +0 -16
- data/lib/rddd/repository_factory.rb +0 -25
- data/lib/rddd/service_factory.rb +0 -21
- data/spec/lib/entity_spec.rb +0 -17
- data/spec/lib/repository_factory_spec.rb +0 -47
- data/spec/lib/repository_spec.rb +0 -26
- data/spec/lib/service_factory_spec.rb +0 -59
- data/spec/lib/service_spec.rb +0 -27
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rddd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby DDD framework
|
15
15
|
email:
|
@@ -30,32 +30,36 @@ files:
|
|
30
30
|
- documentation/rddd.png
|
31
31
|
- lib/core_ext/string.rb
|
32
32
|
- lib/rddd.rb
|
33
|
-
- lib/rddd/
|
34
|
-
- lib/rddd/
|
33
|
+
- lib/rddd/aggregates/entity.rb
|
34
|
+
- lib/rddd/aggregates/finders.rb
|
35
|
+
- lib/rddd/aggregates/repositories/base.rb
|
36
|
+
- lib/rddd/aggregates/repositories/factory.rb
|
37
|
+
- lib/rddd/aggregates/root.rb
|
35
38
|
- lib/rddd/authorization/authorize.rb
|
36
39
|
- lib/rddd/authorization/rule.rb
|
37
40
|
- lib/rddd/authorization/rules_builder.rb
|
38
41
|
- lib/rddd/configuration.rb
|
39
|
-
- lib/rddd/
|
40
|
-
- lib/rddd/
|
41
|
-
- lib/rddd/
|
42
|
-
- lib/rddd/service.rb
|
43
|
-
- lib/rddd/service_bus.rb
|
44
|
-
- lib/rddd/service_factory.rb
|
42
|
+
- lib/rddd/services/service.rb
|
43
|
+
- lib/rddd/services/service_bus.rb
|
44
|
+
- lib/rddd/services/service_factory.rb
|
45
45
|
- lib/rddd/version.rb
|
46
|
+
- lib/rddd/views/cache.rb
|
47
|
+
- lib/rddd/views/cacheable.rb
|
48
|
+
- lib/rddd/views/view.rb
|
46
49
|
- rddd.gemspec
|
47
50
|
- spec/integration_spec.rb
|
48
|
-
- spec/lib/
|
51
|
+
- spec/lib/aggregates/entity_spec.rb
|
52
|
+
- spec/lib/aggregates/root_spec.rb
|
49
53
|
- spec/lib/authorization/authorize_spec.rb
|
50
54
|
- spec/lib/authorization/integration_spec.rb
|
51
55
|
- spec/lib/authorization/rule_spec.rb
|
52
56
|
- spec/lib/authorization/rules_builder_spec.rb
|
53
|
-
- spec/lib/
|
54
|
-
- spec/lib/
|
55
|
-
- spec/lib/
|
56
|
-
- spec/lib/
|
57
|
-
- spec/lib/
|
58
|
-
- spec/lib/
|
57
|
+
- spec/lib/repositories/repository_factory_spec.rb
|
58
|
+
- spec/lib/repositories/repository_spec.rb
|
59
|
+
- spec/lib/services/service_bus_spec.rb
|
60
|
+
- spec/lib/services/service_factory_spec.rb
|
61
|
+
- spec/lib/services/service_spec.rb
|
62
|
+
- spec/lib/views/integration_spec.rb
|
59
63
|
- spec/spec_helper.rb
|
60
64
|
homepage: http://blog.ngneers.com
|
61
65
|
licenses: []
|
@@ -85,16 +89,17 @@ summary: Intention of rddd is to provide basic skeleton for DDD ruby application
|
|
85
89
|
to make it easier to start.
|
86
90
|
test_files:
|
87
91
|
- spec/integration_spec.rb
|
88
|
-
- spec/lib/
|
92
|
+
- spec/lib/aggregates/entity_spec.rb
|
93
|
+
- spec/lib/aggregates/root_spec.rb
|
89
94
|
- spec/lib/authorization/authorize_spec.rb
|
90
95
|
- spec/lib/authorization/integration_spec.rb
|
91
96
|
- spec/lib/authorization/rule_spec.rb
|
92
97
|
- spec/lib/authorization/rules_builder_spec.rb
|
93
|
-
- spec/lib/
|
94
|
-
- spec/lib/
|
95
|
-
- spec/lib/
|
96
|
-
- spec/lib/
|
97
|
-
- spec/lib/
|
98
|
-
- spec/lib/
|
98
|
+
- spec/lib/repositories/repository_factory_spec.rb
|
99
|
+
- spec/lib/repositories/repository_spec.rb
|
100
|
+
- spec/lib/services/service_bus_spec.rb
|
101
|
+
- spec/lib/services/service_factory_spec.rb
|
102
|
+
- spec/lib/services/service_spec.rb
|
103
|
+
- spec/lib/views/integration_spec.rb
|
99
104
|
- spec/spec_helper.rb
|
100
105
|
has_rdoc:
|
data/lib/rddd/aggregate_root.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'rddd/entity'
|
2
|
-
require 'rddd/repository_factory'
|
3
|
-
require 'rddd/aggregate_root_finders'
|
4
|
-
|
5
|
-
module Rddd
|
6
|
-
class AggregateRoot < Entity
|
7
|
-
extend AggregateRootFinders
|
8
|
-
|
9
|
-
finder :find
|
10
|
-
|
11
|
-
[:create, :update, :delete].each do |action|
|
12
|
-
define_method action do
|
13
|
-
self.class.repository.send(action, self)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Rddd
|
2
|
-
module AggregateRootFinders
|
3
|
-
def finder(name)
|
4
|
-
craete_static_method(name) do |*args|
|
5
|
-
repository.send(name, *args)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def repository
|
10
|
-
RepositoryFactory.build(self)
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def craete_static_method(name, &block)
|
16
|
-
(class << self; self; end).instance_eval do
|
17
|
-
define_method name, &block
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/rddd/entity.rb
DELETED
data/lib/rddd/repository.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'rddd/repository'
|
2
|
-
require 'rddd/configuration'
|
3
|
-
|
4
|
-
module Rddd
|
5
|
-
class NotExistingRepository < RuntimeError
|
6
|
-
end
|
7
|
-
|
8
|
-
class RepositoryFactory
|
9
|
-
CreatorNotGiven = Class.new(RuntimeError)
|
10
|
-
|
11
|
-
def self.build(clazz)
|
12
|
-
creator = Configuration.instance.repository_creator
|
13
|
-
|
14
|
-
raise CreatorNotGiven unless creator
|
15
|
-
|
16
|
-
begin
|
17
|
-
repository = creator.call(clazz)
|
18
|
-
rescue
|
19
|
-
raise NotExistingRepository unless repository
|
20
|
-
end
|
21
|
-
|
22
|
-
repository.new
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/rddd/service_factory.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rddd/configuration'
|
2
|
-
|
3
|
-
module Rddd
|
4
|
-
class ServiceFactory
|
5
|
-
CreatorNotGiven = Class.new(RuntimeError)
|
6
|
-
|
7
|
-
InvalidService = Class.new(RuntimeError)
|
8
|
-
|
9
|
-
def self.build(name, attributes)
|
10
|
-
creator = Configuration.instance.service_creator
|
11
|
-
|
12
|
-
raise CreatorNotGiven unless creator
|
13
|
-
|
14
|
-
begin
|
15
|
-
creator.call(name).new(attributes)
|
16
|
-
rescue
|
17
|
-
raise Rddd::ServiceFactory::InvalidService
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/spec/lib/entity_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rddd/entity'
|
3
|
-
|
4
|
-
describe Rddd::Entity do
|
5
|
-
it 'should have identity' do
|
6
|
-
entity = Rddd::Entity.new('1234')
|
7
|
-
|
8
|
-
entity.id.should == '1234'
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'two entities with same identity are equal' do
|
12
|
-
a = Rddd::Entity.new('1234')
|
13
|
-
b = Rddd::Entity.new('1234')
|
14
|
-
|
15
|
-
(a == b).should be_true
|
16
|
-
end
|
17
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rddd/repository_factory'
|
3
|
-
|
4
|
-
describe Rddd::RepositoryFactory do
|
5
|
-
let(:project) { stub('project', :name => 'Foo', :class => stub(:name => 'Foo')) }
|
6
|
-
|
7
|
-
let(:repository_creator) do
|
8
|
-
lambda do |clazz|
|
9
|
-
class_name = "#{clazz.name.to_s.camel_case}Repository"
|
10
|
-
Rddd::Repositories.const_get(class_name.to_sym)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
Rddd.const_set(:Repositories, Module.new)
|
16
|
-
Rddd::Repositories.const_set(:FooRepository, Class.new)
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
Rddd::Repositories.class_eval { remove_const(:FooRepository) }
|
21
|
-
Rddd.class_eval { remove_const(:Repositories) }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '.build' do
|
25
|
-
context 'configuration repository_creator given' do
|
26
|
-
before do
|
27
|
-
Rddd.configure { |config| config.repository_creator = repository_creator }
|
28
|
-
end
|
29
|
-
|
30
|
-
after do
|
31
|
-
Rddd.configure { |config| config.repository_creator = nil }
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should call the appropriate service' do
|
35
|
-
Rddd::Repositories::FooRepository.expects(:new)
|
36
|
-
|
37
|
-
Rddd::RepositoryFactory.build(project.class)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'configuration repository_creator not given' do
|
42
|
-
it 'should raise exception' do
|
43
|
-
expect { Rddd::RepositoryFactory.build(project.class) }.to raise_exception Rddd::RepositoryFactory::CreatorNotGiven
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/spec/lib/repository_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rddd/repository'
|
3
|
-
|
4
|
-
describe Rddd::Repository do
|
5
|
-
let(:repository) { Rddd::Repository.new }
|
6
|
-
|
7
|
-
let(:aggregate_root) { stub('aggregate_root') }
|
8
|
-
|
9
|
-
describe '#create' do
|
10
|
-
subject { repository.create(aggregate_root) }
|
11
|
-
|
12
|
-
it { expect { subject }.to raise_exception NotImplementedError }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#update' do
|
16
|
-
subject { repository.update(aggregate_root) }
|
17
|
-
|
18
|
-
it { expect { subject }.to raise_exception NotImplementedError }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#delete' do
|
22
|
-
subject { repository.delete(aggregate_root) }
|
23
|
-
|
24
|
-
it { expect { subject }.to raise_exception NotImplementedError }
|
25
|
-
end
|
26
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rddd/service_factory'
|
3
|
-
|
4
|
-
describe Rddd::ServiceFactory do
|
5
|
-
let(:attributes) { stub('attributes') }
|
6
|
-
|
7
|
-
let(:service_creator) do
|
8
|
-
lambda do |name|
|
9
|
-
class_name = "#{name.to_s.camel_case}Service"
|
10
|
-
Rddd::Services.const_get(class_name.to_sym)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
Rddd.const_set(:Services, Module.new)
|
16
|
-
Rddd::Services.const_set(:CreateProjectService, Class.new)
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
Rddd::Services.class_eval {remove_const(:CreateProjectService)}
|
21
|
-
Rddd.class_eval {remove_const(:Services)}
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '.build' do
|
25
|
-
context 'configuration service_creator given' do
|
26
|
-
before do
|
27
|
-
Rddd.configure { |config| config.service_creator = service_creator }
|
28
|
-
end
|
29
|
-
|
30
|
-
after do
|
31
|
-
Rddd.configure { |config| config.service_creator = nil }
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should call the appropriate service' do
|
35
|
-
Rddd::Services::CreateProjectService.expects(:new).with(attributes)
|
36
|
-
|
37
|
-
Rddd::ServiceFactory.build(:create_project, attributes)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'not existing service' do
|
42
|
-
before do
|
43
|
-
Rddd.configure { |config| config.service_creator = service_creator }
|
44
|
-
end
|
45
|
-
|
46
|
-
after do
|
47
|
-
Rddd.configure { |config| config.service_creator = nil }
|
48
|
-
end
|
49
|
-
|
50
|
-
it { expect { Rddd::ServiceFactory.build(:foo, attributes) }.to raise_exception Rddd::ServiceFactory::InvalidService }
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'configuration service_creator not given' do
|
54
|
-
it 'should raise exception' do
|
55
|
-
expect { Rddd::ServiceFactory.build(:create_project, attributes) }.to raise_exception Rddd::ServiceFactory::CreatorNotGiven
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/spec/lib/service_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rddd/service'
|
3
|
-
|
4
|
-
describe Rddd::Service do
|
5
|
-
let(:attributes) { stub('attributes') }
|
6
|
-
|
7
|
-
describe '#initialize' do
|
8
|
-
subject { Rddd::Service.new(attributes) }
|
9
|
-
|
10
|
-
it 'should store attributes' do
|
11
|
-
subject.instance_variable_get(:@attributes).should == attributes
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#valid?' do
|
16
|
-
subject { Rddd::Service.new.valid? }
|
17
|
-
it { should be_true }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#execute' do
|
21
|
-
it 'should raise not implemented' do
|
22
|
-
lambda do
|
23
|
-
Rddd::Service.new(attributes).execute
|
24
|
-
end.should raise_exception(NotImplementedError)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|