adaptation 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/helpers/application.rb +6 -0
- data/lib/adaptation/base.rb +31 -19
- data/lib/adaptation/test/test_help.rb +2 -2
- data/lib/rails_generator/generators/applications/app/app_generator.rb +1 -0
- data/lib/rails_generator/generators/components/adaptor/adaptor_generator.rb +1 -1
- data/lib/rails_generator/generators/components/adaptor/templates/adaptor.rb +1 -1
- metadata +63 -62
data/CHANGELOG
CHANGED
@@ -20,3 +20,10 @@
|
|
20
20
|
- in tests, the 'load_message_from_fixture' method gets from the fixture itself the message class
|
21
21
|
to load, not from the test class
|
22
22
|
- fixed publish and assert_message_published methods for testing
|
23
|
+
* 0.1.0
|
24
|
+
- database connection moved from Adaptation::Base.new to Adaptation::Initializer.run. Without this
|
25
|
+
tests didn't connect to database (in tests Adaptation::Base.new is not always executed)
|
26
|
+
- adaptors extend ApplicationAdaptor instead of Adaptation::Base, so common functionality can be
|
27
|
+
placed in ApplicationAdaptor (app/adaptors/application.rb)
|
28
|
+
- if a message is not implemented in the adaptor, ApplicationAdaptor process method will be called
|
29
|
+
with that message as a parameter (wich will be an instance of Adaptation::Message)
|
data/lib/adaptation/base.rb
CHANGED
@@ -12,7 +12,15 @@ module Adaptation
|
|
12
12
|
$config = YAML::load(File.open("#{ADAPTOR_ROOT}/config/settings.yml"))[$environment]
|
13
13
|
end
|
14
14
|
|
15
|
+
# connect with database -> this could also be avoided?
|
16
|
+
if File.exists?("#{ADAPTOR_ROOT}/config/database.yml")
|
17
|
+
environment_configurations = YAML::load(File.open("#{ADAPTOR_ROOT}/config/database.yml"))[$environment]
|
18
|
+
ActiveRecord::Base.configurations.update($environment => environment_configurations)
|
19
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[$environment])
|
20
|
+
end
|
21
|
+
|
15
22
|
# require all adaptors
|
23
|
+
require "#{ADAPTOR_ROOT}/app/adaptors/application.rb" if File.exist?("#{ADAPTOR_ROOT}/app/adaptors/application.rb")
|
16
24
|
Dir["#{ADAPTOR_ROOT}/app/adaptors/*.rb"].each do |f|
|
17
25
|
require f
|
18
26
|
end
|
@@ -34,19 +42,10 @@ module Adaptation
|
|
34
42
|
|
35
43
|
class Base
|
36
44
|
|
37
|
-
attr_reader :logger
|
38
|
-
|
39
45
|
def initialize
|
40
46
|
|
41
47
|
Initializer.run
|
42
48
|
|
43
|
-
# connect with database -> this could also be avoided?
|
44
|
-
if File.exists?("#{ADAPTOR_ROOT}/config/database.yml")
|
45
|
-
environment_configurations = YAML::load(File.open("#{ADAPTOR_ROOT}/config/database.yml"))[$environment]
|
46
|
-
ActiveRecord::Base.configurations.update($environment => environment_configurations)
|
47
|
-
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[$environment])
|
48
|
-
end
|
49
|
-
|
50
49
|
@@logger = Logger.new("#{ADAPTOR_ROOT}/log/#{$environment}.log")
|
51
50
|
ActiveRecord::Base.logger = @@logger
|
52
51
|
|
@@ -59,24 +58,37 @@ module Adaptation
|
|
59
58
|
def process(xml_message)
|
60
59
|
|
61
60
|
# dirty method to discover the message type
|
61
|
+
# TODO: move to a module
|
62
62
|
message_type = xml_message[1..(xml_message.index(/(>| |\/)/) - 1)]
|
63
|
-
|
63
|
+
adaptor = message = nil
|
64
|
+
|
64
65
|
begin
|
65
66
|
message_class = get_class_object(message_type.capitalize)
|
66
67
|
message = message_class.to_object(xml_message)
|
67
|
-
|
68
|
+
rescue
|
69
|
+
# message class not implemented in this adaptor
|
70
|
+
#
|
71
|
+
# TODO: the xml is returned as a String; in future versions
|
72
|
+
# Adaptation may build a valid Adaptation::Message even
|
73
|
+
# without implementation for this type of message
|
74
|
+
message = xml_message # Adaptation::Message.to_object(xml_message)
|
75
|
+
end
|
76
|
+
|
77
|
+
begin
|
68
78
|
adaptor_class = get_class_object("#{message_type.capitalize}Adaptor")
|
69
79
|
adaptor = adaptor_class.new
|
70
|
-
rescue
|
71
|
-
#
|
72
|
-
|
80
|
+
rescue
|
81
|
+
# adaptor class not implemented in this adaptor
|
82
|
+
adaptor = ApplicationAdaptor.new
|
73
83
|
end
|
74
|
-
|
75
|
-
unless message.
|
76
|
-
|
77
|
-
|
84
|
+
|
85
|
+
unless message.is_a?(String) # TODO: remove when feature explained in line 70 implemented
|
86
|
+
unless message.check
|
87
|
+
@@logger.info "WARNING:Message doesn't validate!"
|
88
|
+
return
|
89
|
+
end
|
78
90
|
end
|
79
|
-
|
91
|
+
|
80
92
|
adaptor.process message
|
81
93
|
end
|
82
94
|
|
@@ -262,12 +262,12 @@ class Test::Unit::TestCase
|
|
262
262
|
def load_message_fixture fixture_symbol #:nodoc:
|
263
263
|
data = get_message_fixture(fixture_symbol.to_s)
|
264
264
|
class_name = data[1..(data.index(/(>| )/) - 1)].capitalize
|
265
|
-
message_class = get_class_object(class_name)
|
265
|
+
message_class = get_class_object(class_name) rescue Adaptation::Message
|
266
266
|
message_object = message_class.to_object(data)
|
267
267
|
[data, message_object]
|
268
268
|
end
|
269
269
|
|
270
|
-
# this method is repeated
|
270
|
+
# TODO: this method is repeated in different parts of the code... module?
|
271
271
|
def get_class_object(searched_class) #:nodoc:
|
272
272
|
Object.const_get searched_class
|
273
273
|
end
|
@@ -31,6 +31,7 @@ class AppGenerator < Rails::Generator::Base
|
|
31
31
|
m.file "README", "README"
|
32
32
|
|
33
33
|
# Application
|
34
|
+
m.file "helpers/application.rb", "app/adaptors/application.rb"
|
34
35
|
m.file "helpers/test_helper.rb", "test/test_helper.rb"
|
35
36
|
m.file "helpers/publish.rb", "test/mocks/test/publish.rb"
|
36
37
|
|
@@ -2,7 +2,7 @@ class AdaptorGenerator < Rails::Generator::NamedBase
|
|
2
2
|
def manifest
|
3
3
|
record do |m|
|
4
4
|
# Check for class naming collisions.
|
5
|
-
m.class_collisions class_path, "#{class_name}Adaptor", "#{class_name}AdaptorTest"
|
5
|
+
m.class_collisions class_path, "ApplicationAdaptor", "#{class_name}Adaptor", "#{class_name}AdaptorTest"
|
6
6
|
|
7
7
|
# Adaptors and test directories.
|
8
8
|
m.directory File.join('app/adaptors', class_path)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adaptation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavi Vila Morell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-05 00:00:00 +01:00
|
13
13
|
default_executable: adaptation
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,95 +42,96 @@ extensions: []
|
|
42
42
|
extra_rdoc_files:
|
43
43
|
- README
|
44
44
|
files:
|
45
|
-
- bin/
|
46
|
-
- bin/
|
45
|
+
- bin/subscribe
|
46
|
+
- bin/destroy
|
47
47
|
- bin/breakpointer
|
48
|
-
- bin/
|
48
|
+
- bin/about
|
49
49
|
- bin/adaptation
|
50
|
+
- bin/generate
|
51
|
+
- bin/console
|
50
52
|
- bin/mom
|
51
|
-
- bin/subscribe
|
52
|
-
- bin/destroy
|
53
|
-
- lib/rails_generator
|
54
|
-
- lib/ruby_version_check.rb
|
55
|
-
- lib/breakpoint_client.rb
|
56
|
-
- lib/binding_of_caller.rb
|
57
53
|
- lib/breakpoint.rb
|
58
|
-
- lib/rails_generator.rb
|
59
|
-
- lib/commands.rb
|
60
|
-
- lib/adaptation.rb
|
61
|
-
- lib/commands
|
62
54
|
- lib/adaptation
|
63
|
-
- lib/
|
64
|
-
- lib/
|
65
|
-
- lib/
|
55
|
+
- lib/adaptation/base.rb
|
56
|
+
- lib/adaptation/console
|
57
|
+
- lib/adaptation/console/environment.rb
|
58
|
+
- lib/adaptation/version.rb
|
59
|
+
- lib/adaptation/mom.rb
|
60
|
+
- lib/adaptation/message.rb
|
61
|
+
- lib/adaptation/adaptor.rb
|
62
|
+
- lib/adaptation/druby_subscriber.rb
|
63
|
+
- lib/adaptation/test
|
64
|
+
- lib/adaptation/test/fake_fixtures.rb
|
65
|
+
- lib/adaptation/test/test_help.rb
|
66
|
+
- lib/adaptation/validateable.rb
|
67
|
+
- lib/commands.rb
|
68
|
+
- lib/rails_generator
|
69
|
+
- lib/rails_generator/options.rb
|
66
70
|
- lib/rails_generator/simple_logger.rb
|
67
|
-
- lib/rails_generator/
|
71
|
+
- lib/rails_generator/base.rb
|
68
72
|
- lib/rails_generator/commands.rb
|
69
73
|
- lib/rails_generator/lookup.rb
|
70
|
-
- lib/rails_generator/
|
74
|
+
- lib/rails_generator/manifest.rb
|
71
75
|
- lib/rails_generator/generated_attribute.rb
|
72
|
-
- lib/rails_generator/
|
73
|
-
- lib/rails_generator/
|
76
|
+
- lib/rails_generator/scripts.rb
|
77
|
+
- lib/rails_generator/scripts
|
74
78
|
- lib/rails_generator/scripts/update.rb
|
75
79
|
- lib/rails_generator/scripts/destroy.rb
|
76
80
|
- lib/rails_generator/scripts/generate.rb
|
77
|
-
- lib/rails_generator/
|
81
|
+
- lib/rails_generator/spec.rb
|
82
|
+
- lib/rails_generator/generators
|
78
83
|
- lib/rails_generator/generators/applications
|
79
|
-
- lib/rails_generator/generators/
|
80
|
-
- lib/rails_generator/generators/
|
84
|
+
- lib/rails_generator/generators/applications/app
|
85
|
+
- lib/rails_generator/generators/applications/app/USAGE
|
86
|
+
- lib/rails_generator/generators/applications/app/app_generator.rb
|
87
|
+
- lib/rails_generator/generators/components
|
81
88
|
- lib/rails_generator/generators/components/model
|
82
|
-
- lib/rails_generator/generators/components/
|
89
|
+
- lib/rails_generator/generators/components/model/USAGE
|
90
|
+
- lib/rails_generator/generators/components/model/templates
|
91
|
+
- lib/rails_generator/generators/components/model/templates/unit_test.rb
|
92
|
+
- lib/rails_generator/generators/components/model/templates/fixtures.yml
|
93
|
+
- lib/rails_generator/generators/components/model/templates/migration.rb
|
94
|
+
- lib/rails_generator/generators/components/model/templates/model.rb
|
95
|
+
- lib/rails_generator/generators/components/model/model_generator.rb
|
96
|
+
- lib/rails_generator/generators/components/message
|
83
97
|
- lib/rails_generator/generators/components/message/USAGE
|
84
|
-
- lib/rails_generator/generators/components/message/
|
98
|
+
- lib/rails_generator/generators/components/message/templates
|
99
|
+
- lib/rails_generator/generators/components/message/templates/unit_test.rb
|
85
100
|
- lib/rails_generator/generators/components/message/templates/message.rb
|
86
101
|
- lib/rails_generator/generators/components/message/templates/fixtures.xml
|
87
|
-
- lib/rails_generator/generators/components/message/
|
88
|
-
- lib/rails_generator/generators/components/adaptor
|
89
|
-
- lib/rails_generator/generators/components/adaptor/templates
|
102
|
+
- lib/rails_generator/generators/components/message/message_generator.rb
|
103
|
+
- lib/rails_generator/generators/components/adaptor
|
90
104
|
- lib/rails_generator/generators/components/adaptor/USAGE
|
91
|
-
- lib/rails_generator/generators/components/adaptor/templates
|
105
|
+
- lib/rails_generator/generators/components/adaptor/templates
|
92
106
|
- lib/rails_generator/generators/components/adaptor/templates/adaptor.rb
|
93
|
-
- lib/rails_generator/generators/components/
|
94
|
-
- lib/rails_generator/generators/components/
|
95
|
-
- lib/
|
96
|
-
- lib/rails_generator
|
97
|
-
- lib/
|
98
|
-
- lib/
|
99
|
-
- lib/
|
100
|
-
- lib/rails_generator/generators/applications/app
|
101
|
-
- lib/rails_generator/generators/applications/app/app_generator.rb
|
102
|
-
- lib/rails_generator/generators/applications/app/USAGE
|
103
|
-
- lib/commands/subscribe.rb
|
107
|
+
- lib/rails_generator/generators/components/adaptor/templates/functional_test.rb
|
108
|
+
- lib/rails_generator/generators/components/adaptor/adaptor_generator.rb
|
109
|
+
- lib/binding_of_caller.rb
|
110
|
+
- lib/rails_generator.rb
|
111
|
+
- lib/ruby_version_check.rb
|
112
|
+
- lib/adaptation.rb
|
113
|
+
- lib/commands
|
104
114
|
- lib/commands/breakpointer.rb
|
105
|
-
- lib/commands/
|
115
|
+
- lib/commands/console.rb
|
106
116
|
- lib/commands/about.rb
|
107
117
|
- lib/commands/adaptor_path.rb
|
118
|
+
- lib/commands/subscribe.rb
|
119
|
+
- lib/commands/destroy.rb
|
108
120
|
- lib/commands/generate.rb
|
109
|
-
- lib/
|
110
|
-
-
|
111
|
-
- lib/adaptation/test
|
112
|
-
- lib/adaptation/validateable.rb
|
113
|
-
- lib/adaptation/base.rb
|
114
|
-
- lib/adaptation/message.rb
|
115
|
-
- lib/adaptation/druby_subscriber.rb
|
116
|
-
- lib/adaptation/console
|
117
|
-
- lib/adaptation/mom.rb
|
118
|
-
- lib/adaptation/adaptor.rb
|
119
|
-
- lib/adaptation/test/fake_fixtures.rb
|
120
|
-
- lib/adaptation/test/test_help.rb
|
121
|
-
- lib/adaptation/console/environment.rb
|
122
|
-
- helpers/test_helper.rb
|
123
|
-
- helpers/publish.rb
|
121
|
+
- lib/breakpoint_client.rb
|
122
|
+
- helpers/application.rb
|
124
123
|
- helpers/test.rb
|
124
|
+
- helpers/publish.rb
|
125
|
+
- helpers/test_helper.rb
|
125
126
|
- doc/README_FOR_APP
|
127
|
+
- configs/databases
|
128
|
+
- configs/databases/mysql.yml
|
126
129
|
- configs/mom.yml
|
127
|
-
- configs/empty.log
|
128
130
|
- configs/settings.yml
|
129
|
-
- configs/
|
131
|
+
- configs/empty.log
|
130
132
|
- configs/boot.rb
|
131
|
-
- configs/databases/mysql.yml
|
132
|
-
- dispatches/publish.rb
|
133
133
|
- dispatches/dispatch.rb
|
134
|
+
- dispatches/publish.rb
|
134
135
|
- README
|
135
136
|
- CHANGELOG
|
136
137
|
- fresh_rakefile
|