hoth 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{README.md → README.rdoc} +33 -34
- data/lib/hoth/endpoint.rb +17 -11
- data/lib/hoth/service_module.rb +2 -2
- data/spec/unit/endpoint_spec.rb +5 -22
- data/spec/unit/service_module_spec.rb +6 -1
- metadata +5 -5
data/{README.md → README.rdoc}
RENAMED
@@ -1,16 +1,16 @@
|
|
1
|
-
|
1
|
+
= Hoth
|
2
2
|
|
3
3
|
Creating a SOA requires a centralized location to define all services within the SOA. Furthermore you want to know where those services live.
|
4
4
|
|
5
|
-
|
5
|
+
= How to use
|
6
6
|
|
7
|
-
|
7
|
+
== Install
|
8
8
|
|
9
9
|
gem install hoth
|
10
10
|
|
11
|
-
|
11
|
+
== Define services and modules
|
12
12
|
|
13
|
-
|
13
|
+
=== Service-Definition
|
14
14
|
|
15
15
|
This is how you define services:
|
16
16
|
|
@@ -28,7 +28,7 @@ This definition describes a service with a name, some parameters and its return
|
|
28
28
|
|
29
29
|
A service whith this return value will always return nil. You can also specify `:nil`, with the same result.
|
30
30
|
|
31
|
-
|
31
|
+
=== Module-Definition
|
32
32
|
|
33
33
|
After defining all you services, you need to specify in which modules they live. Each module can be seen as a set of implemented services. Each module can have one or more endpoints. Here is how you define these modules with its endpoints and services:
|
34
34
|
|
@@ -37,29 +37,31 @@ After defining all you services, you need to specify in which modules they live.
|
|
37
37
|
|
38
38
|
service_module :module_name do
|
39
39
|
env :development, :test do
|
40
|
-
endpoint :default
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
endpoint :default do
|
41
|
+
host 'localhost'
|
42
|
+
port 3000
|
43
|
+
transport_type :http
|
44
|
+
end
|
45
|
+
|
46
|
+
endpoint :bert do
|
47
|
+
host 'localhost'
|
48
|
+
port 9999
|
49
|
+
transport_type :bert
|
50
|
+
end
|
50
51
|
end
|
51
52
|
|
52
53
|
env :production do
|
53
|
-
endpoint :default
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
endpoint :default do
|
55
|
+
host '192.168.1.12'
|
56
|
+
port 3000
|
57
|
+
transport_type :http
|
58
|
+
end
|
59
|
+
|
60
|
+
endpoint :bert do
|
61
|
+
host '192.168.1.15'
|
62
|
+
port 9999
|
63
|
+
transport_type :bert
|
64
|
+
end
|
63
65
|
end
|
64
66
|
|
65
67
|
add_service :first_service
|
@@ -71,7 +73,7 @@ After defining all you services, you need to specify in which modules they live.
|
|
71
73
|
|
72
74
|
As you can see, it is possible to define different endpoints for different environments. Each endpoint has a host, a port and a transport-type. After defining your endpoints you can add your previously defined services to the module and define which endpoint they should use. If you do not specify an endpoint the :default endpoint will be used.
|
73
75
|
|
74
|
-
|
76
|
+
== Integrate in your project
|
75
77
|
|
76
78
|
Just execute current code (in rails you can add this line to an initializer):
|
77
79
|
|
@@ -79,17 +81,14 @@ Just execute current code (in rails you can add this line to an initializer):
|
|
79
81
|
|
80
82
|
By default, Hoth looks for the files service_definition and module_definition in the config-Directory (`./config`). If you need to load these files from another place, just set `Hoth.config_path` to your needs.
|
81
83
|
|
82
|
-
|
84
|
+
== Note on Patches/Pull Requests
|
83
85
|
|
84
86
|
* Fork the project.
|
85
87
|
* Make your feature addition or bug fix.
|
86
|
-
* Add tests for it. This is important so I don't break it in a
|
87
|
-
|
88
|
-
* Commit, do not mess with rakefile, version, or history.
|
89
|
-
(if you want to have your own version, that is fine but
|
90
|
-
bump version in a commit by itself I can ignore when I pull)
|
88
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
89
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
91
90
|
* Send me a pull request. Bonus points for topic branches.
|
92
91
|
|
93
|
-
|
92
|
+
== Copyright
|
94
93
|
|
95
94
|
Copyright (c) 2009-2010 Dirk Breuer. See LICENSE for details.
|
data/lib/hoth/endpoint.rb
CHANGED
@@ -1,19 +1,25 @@
|
|
1
1
|
module Hoth
|
2
2
|
class Endpoint
|
3
3
|
attr_accessor :host, :port, :module_name, :transport_type
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
|
5
|
+
class ConfigEvaluator
|
6
|
+
attr_reader :endpoint
|
7
|
+
def initialize(endpoint, &block)
|
8
|
+
@endpoint = endpoint
|
9
|
+
instance_eval(&block)
|
10
|
+
end
|
11
|
+
|
12
|
+
[:host, :port, :module_name, :transport_type].each do |endpoint_attribute|
|
13
|
+
define_method endpoint_attribute do |value|
|
14
|
+
endpoint.send("#{endpoint_attribute}=", value)
|
15
|
+
end
|
16
|
+
end
|
10
17
|
end
|
11
|
-
|
12
|
-
def
|
13
|
-
self
|
14
|
-
self.port == endpoint.port
|
18
|
+
|
19
|
+
def initialize(&block)
|
20
|
+
ConfigEvaluator.new(self, &block)
|
15
21
|
end
|
16
|
-
|
22
|
+
|
17
23
|
def to_url
|
18
24
|
"http://#{@host}:#{@port}/execute"
|
19
25
|
end
|
data/lib/hoth/service_module.rb
CHANGED
@@ -10,8 +10,8 @@ module Hoth
|
|
10
10
|
instance_eval(&block)
|
11
11
|
end
|
12
12
|
|
13
|
-
def endpoint(endpoint_name,
|
14
|
-
@endpoints[endpoint_name.to_sym] = Endpoint.new(
|
13
|
+
def endpoint(endpoint_name, &block)
|
14
|
+
@endpoints[endpoint_name.to_sym] = Endpoint.new(&block)
|
15
15
|
end
|
16
16
|
|
17
17
|
def [](endpoint_name)
|
data/spec/unit/endpoint_spec.rb
CHANGED
@@ -3,44 +3,27 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
3
3
|
describe Hoth::Endpoint do
|
4
4
|
|
5
5
|
it "should have a port" do
|
6
|
-
endpoint = Hoth::Endpoint.new
|
6
|
+
endpoint = Hoth::Endpoint.new { port 3000 }
|
7
7
|
endpoint.port.should == 3000
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should have a host name" do
|
11
|
-
endpoint = Hoth::Endpoint.new
|
11
|
+
endpoint = Hoth::Endpoint.new { host "example.com" }
|
12
12
|
endpoint.host.should == "example.com"
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should have a transport type" do
|
16
|
-
endpoint = Hoth::Endpoint.new
|
16
|
+
endpoint = Hoth::Endpoint.new { transport_type :json }
|
17
17
|
endpoint.transport_type.should == :json
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should should cast itself to URL string" do
|
21
|
-
endpoint = Hoth::Endpoint.new
|
21
|
+
endpoint = Hoth::Endpoint.new { port 3000; host "example.com" }
|
22
22
|
endpoint.to_url.should == "http://example.com:3000/execute"
|
23
23
|
end
|
24
|
-
|
25
|
-
it "should compare to another endpoint" do
|
26
|
-
json_endpoint = Hoth::Endpoint.new(
|
27
|
-
:port => 3000,
|
28
|
-
:host => "example.com",
|
29
|
-
:transport_type => :json
|
30
|
-
)
|
31
|
-
|
32
|
-
bert_endpoint = Hoth::Endpoint.new(
|
33
|
-
:port => 3000,
|
34
|
-
:host => "example.com",
|
35
|
-
:transport_type => :bert
|
36
|
-
)
|
37
24
|
|
38
|
-
json_endpoint.should equal(json_endpoint)
|
39
|
-
json_endpoint.should_not equal(bert_endpoint)
|
40
|
-
end
|
41
|
-
|
42
25
|
it "should should know the deployment module this endpoint is associated to" do
|
43
|
-
endpoint = Hoth::Endpoint.new
|
26
|
+
endpoint = Hoth::Endpoint.new { module_name "TestModule" }
|
44
27
|
endpoint.module_name.should == "TestModule"
|
45
28
|
end
|
46
29
|
|
@@ -42,7 +42,12 @@ module Hoth
|
|
42
42
|
it "should have an endpoint" do
|
43
43
|
endpoint_mock = mock("Endpoint", :null_object => true)
|
44
44
|
|
45
|
-
endpoint_block = Proc.new
|
45
|
+
endpoint_block = Proc.new do
|
46
|
+
endpoint :development do
|
47
|
+
host 'localhost'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
46
51
|
env = ServiceModule::Environment.new(&endpoint_block)
|
47
52
|
env[:development].should_not be(nil)
|
48
53
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dirk Breuer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-30 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -88,9 +88,9 @@ extensions: []
|
|
88
88
|
|
89
89
|
extra_rdoc_files:
|
90
90
|
- LICENSE
|
91
|
-
- README.
|
91
|
+
- README.rdoc
|
92
92
|
files:
|
93
|
-
- README.
|
93
|
+
- README.rdoc
|
94
94
|
- THANKS.md
|
95
95
|
- lib/hoth.rb
|
96
96
|
- lib/hoth/endpoint.rb
|