rddd 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -1
- data/examples/remoting/app/Gemfile +4 -0
- data/examples/remoting/app/Gemfile.lock +25 -0
- data/examples/remoting/app/app.rb +21 -0
- data/examples/remoting/app/config.ru +3 -0
- data/examples/remoting/app/views/projects.erb +11 -0
- data/examples/remoting/readme.md +31 -0
- data/examples/remoting/remote/Gemfile +5 -0
- data/examples/remoting/remote/Gemfile.lock +37 -0
- data/examples/remoting/remote/app.rb +25 -0
- data/examples/remoting/remote/config.ru +3 -0
- data/examples/remoting/remote/services/list_service.rb +23 -0
- data/lib/rddd/services/remote_service.rb +3 -1
- data/lib/rddd/version.rb +1 -1
- data/rddd.gemspec +2 -0
- data/spec/lib/services/remote_service_spec.rb +4 -3
- metadata +29 -2
data/Gemfile.lock
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ~/development/rddd
|
3
|
+
specs:
|
4
|
+
rddd (0.2.4)
|
5
|
+
curb
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
curb (0.8.3)
|
11
|
+
rack (1.4.4)
|
12
|
+
rack-protection (1.3.2)
|
13
|
+
rack
|
14
|
+
sinatra (1.3.3)
|
15
|
+
rack (~> 1.3, >= 1.3.6)
|
16
|
+
rack-protection (~> 1.2)
|
17
|
+
tilt (~> 1.3, >= 1.3.3)
|
18
|
+
tilt (1.3.3)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
rddd!
|
25
|
+
sinatra
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'rddd'
|
3
|
+
require 'rddd/services/service_bus'
|
4
|
+
|
5
|
+
Rddd.configure do |config|
|
6
|
+
config.remote_services = [
|
7
|
+
{:namespace => :projects, :endpoint => 'http://localhost:9393/service/'}
|
8
|
+
]
|
9
|
+
end
|
10
|
+
|
11
|
+
class App < Sinatra::Base
|
12
|
+
include Rddd::Services::ServiceBus
|
13
|
+
|
14
|
+
get '/' do
|
15
|
+
name = params[:name]
|
16
|
+
body = name ? {:name => name} : {}
|
17
|
+
@data = execute_service(:projects__list, body)
|
18
|
+
|
19
|
+
erb :projects
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Remoting
|
2
|
+
|
3
|
+
Remote service execution is one of the cool features built within the rDDD framework, which would unobtrusively allow
|
4
|
+
you, to split your application into multiple pieces as you
|
5
|
+
go.
|
6
|
+
|
7
|
+
Because all the services are executed through the service bus
|
8
|
+
you are able to detach subset of your application services
|
9
|
+
to its separate server instance without any further changes
|
10
|
+
to your client code or services themselves. All you need to
|
11
|
+
do is to configure the namespaces and endpoints, so framework
|
12
|
+
knows where to find the remote instance.
|
13
|
+
|
14
|
+
Example consists of two Sinatra applications. ```Remote``` is the remote instance with (dummy) domain logic. ```App``` is the main application which calls service from the remote.
|
15
|
+
|
16
|
+
## Run example
|
17
|
+
|
18
|
+
Open first console:
|
19
|
+
|
20
|
+
cd examples/remoting/remote/
|
21
|
+
bundle
|
22
|
+
rackup -p 9393
|
23
|
+
|
24
|
+
Open other console:
|
25
|
+
|
26
|
+
cd examples/remoting/app/
|
27
|
+
bundle
|
28
|
+
rackup
|
29
|
+
|
30
|
+
Now you can access ```http://localhost:9292/``` which would load json document from the remote instance. Try ```http://localhost:9292/?name=Rails``` which filter the output. All the logic is in ```remoting/remote/services/list_service.rb```.
|
31
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ~/development/rddd
|
3
|
+
specs:
|
4
|
+
rddd (0.2.4)
|
5
|
+
curb
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
backports (2.7.0)
|
11
|
+
curb (0.8.3)
|
12
|
+
eventmachine (1.0.0)
|
13
|
+
rack (1.4.4)
|
14
|
+
rack-protection (1.3.2)
|
15
|
+
rack
|
16
|
+
rack-test (0.6.2)
|
17
|
+
rack (>= 1.0)
|
18
|
+
sinatra (1.3.3)
|
19
|
+
rack (~> 1.3, >= 1.3.6)
|
20
|
+
rack-protection (~> 1.2)
|
21
|
+
tilt (~> 1.3, >= 1.3.3)
|
22
|
+
sinatra-contrib (1.3.2)
|
23
|
+
backports (>= 2.0)
|
24
|
+
eventmachine
|
25
|
+
rack-protection
|
26
|
+
rack-test
|
27
|
+
sinatra (~> 1.3.0)
|
28
|
+
tilt (~> 1.3)
|
29
|
+
tilt (1.3.3)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
rddd!
|
36
|
+
sinatra
|
37
|
+
sinatra-contrib
|
@@ -0,0 +1,25 @@
|
|
1
|
+
dir = "#{File.dirname(__FILE__)}/"
|
2
|
+
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
|
3
|
+
|
4
|
+
require 'sinatra'
|
5
|
+
require "sinatra/json"
|
6
|
+
require 'rddd'
|
7
|
+
require 'rddd/services/service_bus'
|
8
|
+
|
9
|
+
require 'services/list_service'
|
10
|
+
|
11
|
+
Rddd.configure do |config|
|
12
|
+
config.service_creator = lambda do |name|
|
13
|
+
class_name = "#{name.to_s.camel_case}Service"
|
14
|
+
puts class_name
|
15
|
+
Object.const_get(class_name.to_sym)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class App < Sinatra::Base
|
20
|
+
include Rddd::Services::ServiceBus
|
21
|
+
|
22
|
+
post '/service/:service_name' do
|
23
|
+
JSON.unparse(execute_service(params[:service_name], JSON.parse(request.body.read)))
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rddd/services/service'
|
2
|
+
|
3
|
+
class ListService < Rddd::Services::Service
|
4
|
+
def execute
|
5
|
+
projects = [
|
6
|
+
{
|
7
|
+
:name => 'rDDD',
|
8
|
+
:deathline => Date.parse('1st Jan 2014'),
|
9
|
+
:description => 'Domain driven design framework'
|
10
|
+
},
|
11
|
+
|
12
|
+
{
|
13
|
+
:name => 'Rails',
|
14
|
+
:deathline => Date.parse('1st Jan 2015'),
|
15
|
+
:description => 'Most popular Ruby framework'
|
16
|
+
}
|
17
|
+
]
|
18
|
+
|
19
|
+
@attributes['name'] ? \
|
20
|
+
projects.select {|project| project[:name] == @attributes['name']} : \
|
21
|
+
projects
|
22
|
+
end
|
23
|
+
end
|
@@ -44,7 +44,9 @@ module Rddd
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def execute
|
47
|
-
JSON.parse(Curl.post(@url, @attributes)
|
47
|
+
JSON.parse(Curl.post(@url, JSON.unparse(@attributes)) do |http|
|
48
|
+
http.headers['Content-Type'] = 'application/json'
|
49
|
+
end.body_str)
|
48
50
|
end
|
49
51
|
|
50
52
|
def self.build(namespace, service_name, attributes)
|
data/lib/rddd/version.rb
CHANGED
data/rddd.gemspec
CHANGED
@@ -4,7 +4,7 @@ require 'rddd/services/remote_service'
|
|
4
4
|
module Rddd
|
5
5
|
module Services
|
6
6
|
describe RemoteService do
|
7
|
-
let(:attributes) {
|
7
|
+
let(:attributes) { {:foo => 'bar'} }
|
8
8
|
|
9
9
|
let(:url) { 'http://remote.dev/' }
|
10
10
|
|
@@ -25,10 +25,11 @@ module Rddd
|
|
25
25
|
describe '#execute' do
|
26
26
|
subject { RemoteService.new(url, attributes).execute }
|
27
27
|
|
28
|
-
let(:curl) { stub('curl', :body_str => '{"foo": "bar"}')}
|
28
|
+
let(:curl) { stub('curl', :body_str => '{"foo": "bar"}', :headers => [])}
|
29
29
|
|
30
30
|
it 'should raise not implemented' do
|
31
|
-
Curl.expects(:post).with(url, attributes).returns(curl)
|
31
|
+
Curl.expects(:post).with(url, JSON.unparse(attributes)).yields(curl).returns(curl)
|
32
|
+
curl.headers.expects(:[]=).with('Content-Type', 'application/json')
|
32
33
|
|
33
34
|
subject.should == {'foo' => 'bar'}
|
34
35
|
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,23 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-01-19 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: curb
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Ruby DDD framework
|
15
31
|
email:
|
16
32
|
- petrjanda@me.com
|
@@ -29,6 +45,17 @@ files:
|
|
29
45
|
- Rakefile
|
30
46
|
- documentation/rddd-elements.png
|
31
47
|
- documentation/rddd.png
|
48
|
+
- examples/remoting/app/Gemfile
|
49
|
+
- examples/remoting/app/Gemfile.lock
|
50
|
+
- examples/remoting/app/app.rb
|
51
|
+
- examples/remoting/app/config.ru
|
52
|
+
- examples/remoting/app/views/projects.erb
|
53
|
+
- examples/remoting/readme.md
|
54
|
+
- examples/remoting/remote/Gemfile
|
55
|
+
- examples/remoting/remote/Gemfile.lock
|
56
|
+
- examples/remoting/remote/app.rb
|
57
|
+
- examples/remoting/remote/config.ru
|
58
|
+
- examples/remoting/remote/services/list_service.rb
|
32
59
|
- lib/core_ext/string.rb
|
33
60
|
- lib/rddd.rb
|
34
61
|
- lib/rddd/aggregates/entity.rb
|