adaptation 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,4 @@
1
1
  * 0.0.3
2
2
  - changed script/mom to mom as a standalone executable (like adaptation)
3
+ * 0.0.4
4
+ - added console and debugger
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ unless defined? ADAPTOR_ROOT
3
+ ADAPTOR_ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
4
+ end
5
+ require "#{ADAPTOR_ROOT}/config/boot"
6
+ require 'rubygems'
7
+ gem 'adaptation'
8
+ require 'commands/console'
9
+
@@ -1,9 +1,16 @@
1
1
  unless defined? ADAPTOR_ROOT
2
2
  ADAPTOR_ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
3
3
  end
4
- require 'yaml'
5
4
 
6
- config = YAML::load(File.open("#{ADAPTOR_ROOT}/config/mom.yml"))
5
+ environment = "development"
6
+ ARGV.each do |arg|
7
+ if arg[0..14] == "ADAPTATION_ENV="
8
+ environment = arg[15..arg.length]
9
+ end
10
+ end
11
+
12
+ require 'yaml'
13
+ config = YAML::load(File.open("#{ADAPTOR_ROOT}/config/mom.yml"))[environment.to_s]
7
14
 
8
15
  case config["mom"]["type"]
9
16
  when "druby"
@@ -31,7 +31,7 @@ module Adaptation
31
31
 
32
32
  def process(xml_message)
33
33
  # dirty method to discover the message type
34
- message_type = xml_message[1..(xml_message.index(/(>| )/) - 1)]
34
+ message_type = xml_message[1..(xml_message.index(/(>| |\/)/) - 1)]
35
35
 
36
36
  begin
37
37
  message_class = get_class_object(message_type.capitalize)
@@ -53,16 +53,17 @@ module Adaptation
53
53
  end
54
54
 
55
55
  def get_class_object(searched_class)
56
- class_object = nil
57
- ObjectSpace.each_object(Class){|aClass|
58
- class_object = aClass if aClass.to_s == searched_class
59
- }
60
- if class_object.nil?
61
- #puts "Unknown class #{searched_class}."
62
- raise Exception.new("Unknown class #{searched_class}.")
63
- else
64
- return class_object
65
- end
56
+ #class_object = nil
57
+ #ObjectSpace.each_object(Class){|aClass|
58
+ # class_object = aClass if aClass.to_s == searched_class
59
+ #}
60
+ #if class_object.nil?
61
+ # #puts "Unknown class #{searched_class}."
62
+ # raise Exception.new("Unknown class #{searched_class}.")
63
+ #else
64
+ # return class_object
65
+ #end
66
+ Object.const_get searched_class
66
67
  end
67
68
 
68
69
  end
@@ -0,0 +1,42 @@
1
+ require 'yaml'
2
+ $environment = "development"
3
+ $config = YAML::load(File.open("#{ADAPTOR_ROOT}/config/settings.yml"))[$environment]
4
+ Adaptation::Base.new
5
+ # connect to test database
6
+ require 'active_record'
7
+
8
+ if File.exists?("#{ADAPTOR_ROOT}/config/database.yml")
9
+ configurations = YAML::load(File.open("#{ADAPTOR_ROOT}/config/database.yml"))[$environment]
10
+ ActiveRecord::Base.configurations.update($environment => configurations)
11
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[$environment])
12
+ end
13
+
14
+ if File.exists?("log")
15
+ ActiveRecord::Base.logger = Logger.new("#{ADAPTOR_ROOT}/log/"+$environment+".log")
16
+ end
17
+
18
+ def get_xml_from_file xml_file
19
+ contents = new Array
20
+ File.open(xml_file).each { |line|
21
+ unless line =~ /^ {0,}#/
22
+ contents << line.strip.chomp
23
+ end
24
+ }
25
+ "#{contents.chomp}"
26
+ end
27
+
28
+ def xml_to_object xml_message
29
+ class_name = xml_message[1..(xml_message.index(/(>| )/) - 1)]
30
+ message_class = Object.const_get(class_name.capitalize)
31
+ message_object = message_class.to_object(xml_message)
32
+ message_object
33
+ end
34
+
35
+ def xmlfile_to_object xml_file
36
+ xml_message = get_xml_from_file(xml_file.to_s)
37
+ message_object = xml_to_object xml_message
38
+ message_object
39
+ end
40
+
41
+
42
+
@@ -15,8 +15,8 @@ module Adaptation
15
15
  end
16
16
 
17
17
  def process message, topic
18
- if ( (@topics.include?(topic)) or (@topics == "all") )
19
- system("ruby public/dispatch.rb #{message}")
18
+ if ( (@topics.include?(topic)) or (@topics.include?("all")) )
19
+ system("ruby public/dispatch.rb '#{message}'")
20
20
  end
21
21
  puts "#{topic} => #{message}"
22
22
  end
@@ -288,15 +288,16 @@ module Adaptation
288
288
  end
289
289
 
290
290
  def self.get_class_object(searched_class)
291
- class_object = nil
292
- ObjectSpace.each_object(Class){|aClass|
293
- class_object = aClass if aClass.to_s == searched_class
294
- }
295
- if class_object.nil?
296
- raise Exception.new("Unknown class #{searched_class}.")
297
- else
298
- return class_object
299
- end
291
+ #class_object = nil
292
+ #ObjectSpace.each_object(Class){|aClass|
293
+ # class_object = aClass if aClass.to_s == searched_class
294
+ #}
295
+ #if class_object.nil?
296
+ # raise Exception.new("Unknown class #{searched_class}.")
297
+ #else
298
+ # return class_object
299
+ #end
300
+ Object.const_get searched_class
300
301
  end
301
302
 
302
303
  def self.get_validations_array
@@ -0,0 +1,4 @@
1
+ class Test::Unit::TestCase
2
+ def self.fixtures symbol
3
+ end
4
+ end
@@ -4,6 +4,11 @@ if File.exists?("config/settings.yml")
4
4
  $config = YAML::load(File.open("config/settings.yml"))[$environment]
5
5
  end
6
6
 
7
+ # for adaptations that require models from a rails application, sometimes
8
+ # rails needs to load the environment.rb from the rails app. When this happens
9
+ # the following variable must be set.
10
+ ENV['RAILS_ENV'] = "test"
11
+
7
12
  # connect to test database
8
13
  require 'active_record'
9
14
 
@@ -273,16 +278,18 @@ class Test::Unit::TestCase
273
278
  [data, message_object]
274
279
  end
275
280
 
281
+ # this method is repeated many times all over the code!
276
282
  def get_class_object(searched_class) #:nodoc:
277
- class_object = nil
278
- ObjectSpace.each_object(Class){|aClass|
279
- class_object = aClass if aClass.to_s == searched_class
280
- }
281
- if class_object.nil?
282
- raise Exception.new("Unknown class #{searched_class}.")
283
- else
284
- return class_object
285
- end
283
+ #class_object = nil
284
+ #ObjectSpace.each_object(Class){|aClass|
285
+ # class_object = aClass if aClass.to_s == searched_class
286
+ #}
287
+ #if class_object.nil?
288
+ # raise Exception.new("Unknown class #{searched_class}.")
289
+ #else
290
+ # return class_object
291
+ #end
292
+ Object.const_get searched_class
286
293
  end
287
294
 
288
295
  def compare_xml_elements element1, element2 #:nodoc:
@@ -0,0 +1 @@
1
+ ADAPTOR_ROOT = "/usr/share/oademand/sugarcrm4.5/installer"
@@ -0,0 +1,34 @@
1
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
2
+
3
+ libs = " -r irb/completion"
4
+ libs << " -r readline"
5
+ libs << " -r rubygems"
6
+ require 'rubygems'
7
+
8
+ begin
9
+ exists_debug_lib = require 'ruby-debug'
10
+ if !exists_debug_lib.nil? && exists_debug_lib == true
11
+ libs << " -r ruby-debug"
12
+ end
13
+ puts "Console have installed \"ruby-debug\" library."
14
+ rescue Exception => e
15
+ puts "Console haven't installed \"ruby-debug\" library."
16
+ end
17
+
18
+ libs << " -r adaptation"
19
+
20
+ if RUBY_PLATFORM =~ /(:?mswin|mingw)/
21
+ ENV_PATH = "/windows/temp"
22
+ else
23
+ ENV_PATH = "/tmp"
24
+ end
25
+
26
+ f = File.new("#{ENV_PATH}/adaptor_path.rb", "w")
27
+ path="ADAPTOR_ROOT = \"" + "#{ADAPTOR_ROOT}\""
28
+ f.write("#{path}")
29
+ f.close
30
+
31
+ libs << " -r #{ENV_PATH}/adaptor_path.rb"
32
+ libs << " -r adaptation/console/environment"
33
+ exec "#{irb} #{libs} --simple-prompt"
34
+
@@ -57,7 +57,7 @@ class AppGenerator < Rails::Generator::Base
57
57
  #m.file "environments/test.rb", "config/environments/test.rb"
58
58
 
59
59
  # Scripts
60
- %w( generate destroy about subscribe breakpointer ).each do |file|
60
+ %w( generate destroy about subscribe breakpointer console ).each do |file|
61
61
  m.file "bin/#{file}", "script/#{file}", script_options
62
62
  end
63
63
 
@@ -1,6 +1,6 @@
1
1
  class <%= class_name %>Adaptor < Adaptation::Adaptor
2
2
 
3
- def process
3
+ def process <%= class_name.downcase %>
4
4
  end
5
5
 
6
6
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: adaptation
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.3
7
- date: 2007-04-30 00:00:00 +02:00
6
+ version: 0.0.4
7
+ date: 2008-06-11 00:00:00 +02:00
8
8
  summary: Framework to facilitate web-application interaction.
9
9
  require_paths:
10
10
  - lib
@@ -29,92 +29,91 @@ post_install_message:
29
29
  authors:
30
30
  - Xavi Vila Morell
31
31
  files:
32
- - bin/generate
32
+ - bin/subscribe
33
33
  - bin/destroy
34
- - bin/adaptation
35
- - bin/about
36
34
  - bin/breakpointer
37
- - bin/mom~
35
+ - bin/about
36
+ - bin/adaptation
37
+ - bin/generate
38
+ - bin/console
38
39
  - bin/mom
39
- - bin/subscribe
40
- - lib/rails_generator.rb
41
- - lib/adaptation
42
- - lib/binding_of_caller.rb
43
- - lib/breakpoint_client.rb
44
- - lib/adaptation.rb
45
- - lib/commands.rb
46
40
  - lib/breakpoint.rb
47
- - lib/commands
48
- - lib/ruby_version_check.rb
49
- - lib/rails_generator
41
+ - lib/adaptation
42
+ - lib/adaptation/base.rb
43
+ - lib/adaptation/console
44
+ - lib/adaptation/console/environment.rb
50
45
  - lib/adaptation/version.rb
51
- - lib/adaptation/mom.rb~
46
+ - lib/adaptation/mom.rb
52
47
  - lib/adaptation/message.rb
53
48
  - lib/adaptation/adaptor.rb
54
49
  - lib/adaptation/druby_subscriber.rb
55
- - lib/adaptation/druby_subscriber.rb~
56
- - lib/adaptation/mom.rb
57
50
  - lib/adaptation/test
58
- - lib/adaptation/oapdaemon.rb~
59
- - lib/adaptation/base.rb
51
+ - lib/adaptation/test/fake_fixtures.rb
60
52
  - lib/adaptation/test/test_help.rb
61
- - lib/commands/mom.rb.descartat
62
- - lib/commands/subscribe.rb~
63
- - lib/commands/destroy.rb
64
- - lib/commands/subscribe.rb
65
- - lib/commands/about.rb
66
- - lib/commands/breakpointer.rb
67
- - lib/commands/generate.rb
68
- - lib/rails_generator/lookup.rb
69
- - lib/rails_generator/generators
70
- - lib/rails_generator/commands.rb
71
- - lib/rails_generator/scripts.rb
72
- - lib/rails_generator/simple_logger.rb
53
+ - lib/commands.rb
54
+ - lib/rails_generator
73
55
  - lib/rails_generator/options.rb
74
- - lib/rails_generator/spec.rb
56
+ - lib/rails_generator/simple_logger.rb
57
+ - lib/rails_generator/base.rb
58
+ - lib/rails_generator/commands.rb
59
+ - lib/rails_generator/lookup.rb
75
60
  - lib/rails_generator/manifest.rb
76
- - lib/rails_generator/scripts
77
61
  - lib/rails_generator/generated_attribute.rb
78
- - lib/rails_generator/base.rb
79
- - lib/rails_generator/generators/components
62
+ - lib/rails_generator/scripts.rb
63
+ - lib/rails_generator/scripts
64
+ - lib/rails_generator/scripts/update.rb
65
+ - lib/rails_generator/scripts/destroy.rb
66
+ - lib/rails_generator/scripts/generate.rb
67
+ - lib/rails_generator/spec.rb
68
+ - lib/rails_generator/generators
80
69
  - lib/rails_generator/generators/applications
70
+ - lib/rails_generator/generators/applications/app
71
+ - lib/rails_generator/generators/applications/app/USAGE
72
+ - lib/rails_generator/generators/applications/app/app_generator.rb
73
+ - lib/rails_generator/generators/components
81
74
  - lib/rails_generator/generators/components/model
82
- - lib/rails_generator/generators/components/adaptor
83
- - lib/rails_generator/generators/components/message
84
75
  - lib/rails_generator/generators/components/model/USAGE
85
- - lib/rails_generator/generators/components/model/model_generator.rb
86
76
  - lib/rails_generator/generators/components/model/templates
87
77
  - lib/rails_generator/generators/components/model/templates/unit_test.rb
88
78
  - lib/rails_generator/generators/components/model/templates/fixtures.yml
89
- - lib/rails_generator/generators/components/model/templates/model.rb
90
79
  - lib/rails_generator/generators/components/model/templates/migration.rb
91
- - lib/rails_generator/generators/components/adaptor/USAGE
92
- - lib/rails_generator/generators/components/adaptor/adaptor_generator.rb
93
- - lib/rails_generator/generators/components/adaptor/templates
94
- - lib/rails_generator/generators/components/adaptor/templates/adaptor.rb
95
- - lib/rails_generator/generators/components/adaptor/templates/functional_test.rb
80
+ - lib/rails_generator/generators/components/model/templates/model.rb
81
+ - lib/rails_generator/generators/components/model/model_generator.rb
82
+ - lib/rails_generator/generators/components/message
96
83
  - lib/rails_generator/generators/components/message/USAGE
97
- - lib/rails_generator/generators/components/message/message_generator.rb
98
84
  - lib/rails_generator/generators/components/message/templates
99
- - lib/rails_generator/generators/components/message/templates/message.rb
100
85
  - lib/rails_generator/generators/components/message/templates/unit_test.rb
86
+ - lib/rails_generator/generators/components/message/templates/message.rb
101
87
  - lib/rails_generator/generators/components/message/templates/fixtures.xml
102
- - lib/rails_generator/generators/applications/app
103
- - lib/rails_generator/generators/applications/app/USAGE
104
- - lib/rails_generator/generators/applications/app/app_generator.rb~
105
- - lib/rails_generator/generators/applications/app/app_generator.rb
106
- - lib/rails_generator/scripts/destroy.rb
107
- - lib/rails_generator/scripts/update.rb
108
- - lib/rails_generator/scripts/generate.rb
88
+ - lib/rails_generator/generators/components/message/message_generator.rb
89
+ - lib/rails_generator/generators/components/adaptor
90
+ - lib/rails_generator/generators/components/adaptor/USAGE
91
+ - lib/rails_generator/generators/components/adaptor/templates
92
+ - lib/rails_generator/generators/components/adaptor/templates/adaptor.rb
93
+ - lib/rails_generator/generators/components/adaptor/templates/functional_test.rb
94
+ - lib/rails_generator/generators/components/adaptor/adaptor_generator.rb
95
+ - lib/binding_of_caller.rb
96
+ - lib/rails_generator.rb
97
+ - lib/ruby_version_check.rb
98
+ - lib/adaptation.rb
99
+ - lib/commands
100
+ - lib/commands/breakpointer.rb
101
+ - lib/commands/console.rb
102
+ - lib/commands/about.rb
103
+ - lib/commands/adaptor_path.rb
104
+ - lib/commands/subscribe.rb
105
+ - lib/commands/destroy.rb
106
+ - lib/commands/generate.rb
107
+ - lib/breakpoint_client.rb
109
108
  - helpers/publish.rb
110
109
  - helpers/test_helper.rb
111
110
  - doc/README_FOR_APP
112
111
  - configs/databases
112
+ - configs/databases/mysql.yml
113
+ - configs/mom.yml
113
114
  - configs/settings.yml
114
115
  - configs/empty.log
115
116
  - configs/boot.rb
116
- - configs/mom.yml
117
- - configs/databases/mysql.yml
118
117
  - dispatches/dispatch.rb
119
118
  - dispatches/publish.rb
120
119
  - README
data/bin/mom~ DELETED
@@ -1,46 +0,0 @@
1
- require 'rubygems'
2
- require 'adaptation'
3
- require 'adaptation/mom'
4
-
5
- DEFAULT_HOST = "127.0.0.1"
6
- DEFAULT_PORT = "8080"
7
-
8
- # search mom configuration file.
9
- # - first by specified parameter
10
- # - second in /etc/adaptation (*nix systems)
11
- # - third in the gem itself
12
-
13
- if File.exists?(File.dirname(__FILE__) + '/../configs/mom.yml')
14
- file = File.dirname(__FILE__) + '/../configs/mom.yml'
15
- end
16
-
17
- if File.exists?('/etc/adaptation/mom.yml')
18
- file = '/etc/adaptation/mom.yml'
19
- end
20
-
21
- if %w(--file -f).include? ARGV.first
22
- file = ARGV[1]
23
- end
24
-
25
- #if %w(--environment -e).include? ARGV.first
26
- # environment = ARGV[1]
27
- #end
28
- environment = "development"
29
-
30
- if file.nil?
31
- config = {"mom" => {"type" => "druby", "host" => DEFAULT_HOST, "port" => DEFAULT_PORT}}
32
- else
33
- config = YAML::load(File.open(file))[environment]
34
- end
35
-
36
- Signal.trap("INT") { puts "Shutting down MOM server (#{config["mom"]["type"]})"; exit }
37
-
38
- case config["mom"]["type"]
39
- when "druby"
40
- mom_uri = "druby://#{config["mom"]["host"]}:#{config["mom"]["port"]}"
41
- mom = Adaptation::Mom::Mom.new mom_uri
42
- mom.start
43
- #when "xmlblaster"
44
- else
45
- puts "Unknown MOM server type: #{config["mom"]["type"]}"
46
- end
@@ -1,79 +0,0 @@
1
- require 'drb'
2
- require 'yaml'
3
-
4
- module Adaptation
5
-
6
- module Mom
7
-
8
- class DrubySubscriber
9
-
10
- def initialize subscriber_uri, mom_uri, topics
11
- @subscriber_uri = subscriber_uri
12
- @mom_uri = mom_uri
13
- @topics = topics
14
- @adaptors_list = Array.new
15
- end
16
-
17
- def process message, topic
18
- if ( (@topics.include?(topic)) or (@topics == "all") )
19
- system("ruby public/dispatch.rb #{message}")
20
- end
21
- puts "#{topic} => #{message}"
22
- end
23
-
24
- def subscription_result subscribed
25
- if subscribed
26
- puts "Subscribed to mom (#{@mom_uri}). Listening at #{@subscriber_uri}"
27
- end
28
- end
29
-
30
- # TODO: Think what exactly is this subscriber:
31
- # - path to file
32
- # - combination of a path and a set of conditions <- looks better...
33
- # - ...
34
- def note_me_down adaptor
35
- unless @adaptors_list.include? adaptor
36
- @adaptors_list << adaptor
37
- puts "Added adaptor: #{adaptor}"
38
- end
39
- end
40
-
41
- def start
42
- begin
43
- # try to start the subscriber service,
44
- # using the uri specified in config/mom.yml
45
- DRb.start_service(@subscriber_uri, self)
46
-
47
- # subscribe that uri to the mom
48
- mom = DRbObject.new(nil, @mom_uri)
49
- mom.subscribe @subscriber_uri
50
- rescue Exception => e
51
- # desired uri already in use...
52
- # if the process using it is a subscriber, this
53
- # shouldn't be a problem
54
- end
55
-
56
- # try to tell to the subscriber using the uri
57
- # (may be this self instance of DrubySubscriber),
58
- # that we want to be executed when the MOM
59
- # calls its process method
60
- begin
61
- subscriber = DRbObject.new(nil, @subscriber_uri)
62
- routes_file = File.expand_path(File.dirname(__FILE__) + '/../config/routes.rb')
63
- subscriber.note_me_down routes_file
64
- rescue Exception => e
65
- # the process using @subscriber_uri is not
66
- # an instance of DrubySubsciber...
67
- puts "Couldn't start or find subscriber at #{@subscriber_uri}:"
68
- puts "#{e}"
69
- return
70
- end
71
-
72
- DRb.thread.join # Don't exit just yet!
73
- end
74
-
75
- end
76
-
77
- end
78
-
79
- end
@@ -1,74 +0,0 @@
1
- require 'drb'
2
- require 'yaml'
3
-
4
- module Adaptation
5
-
6
- module Mom
7
-
8
- class Mom
9
-
10
- def initialize mom_uri
11
- @mom_uri = mom_uri
12
- end
13
-
14
- def subscribe drb_uri
15
- unless get_subscribers.include?(drb_uri)
16
- add_subscriber drb_uri
17
- puts "Added new subscriber: #{drb_uri}"
18
- oapdaemon = DRbObject.new(nil, drb_uri)
19
- oapdaemon.subscription_result true
20
- end
21
- end
22
-
23
- def publish message, topic
24
- # Tell subscribed hosts to execute their adaptors
25
- puts "-----------------------------------"
26
- puts "Received message in topic: #{topic}"
27
- puts "#{message}"
28
- puts "-----------------------------------"
29
- get_subscribers.each do |uri|
30
- puts "Calling #{uri}"
31
- DRb.start_service
32
- oapdaemon = DRbObject.new(nil, uri)
33
- oapdaemon.call_adaptor message, topic
34
- end
35
- end
36
-
37
- def start
38
- DRb.start_service(@mom_uri, self)
39
- puts "MOM started. Listening at #{@mom_uri}"
40
- DRb.thread.join # Don't exit just yet
41
- end
42
-
43
- def list
44
- puts "MOM subscriptions:"
45
- get_subscribers.each do |s|
46
- puts " #{s}"
47
- end
48
- return
49
- end
50
-
51
- private
52
-
53
- def add_subscriber drb_uri
54
- subscribers = get_subscribers
55
- subscribers << drb_uri unless subscribers.include?(drb_uri)
56
- sf = File.new('subscribers.yml', 'w')
57
- sf.write(YAML::dump(subscribers))
58
- sf.close
59
- end
60
-
61
- def get_subscribers
62
- if File.exists?('subscribers.yml')
63
- subscribers = YAML::load(File.open('subscribers.yml'))
64
- else
65
- subscribers = Array.new
66
- end
67
- subscribers
68
- end
69
-
70
- end
71
-
72
- end
73
-
74
- end
@@ -1,42 +0,0 @@
1
- require 'drb'
2
- require 'yaml'
3
-
4
- module Adaptation
5
-
6
- module Mom
7
-
8
- class druby_subscriber
9
-
10
- def initialize subscriber_uri, mom_uri, topics
11
- @subscriber_uri = subscriber_uri
12
- @mom_uri = mom_uri
13
- @topics = topics
14
- end
15
-
16
- def call_adaptor message, topic
17
- if ( (@topics.include?(topic)) or (@topics == "all") )
18
- system("ruby public/dispatch.rb #{message}")
19
- end
20
- puts "#{topic} => #{message}"
21
- end
22
-
23
- def subscription_result subscribed
24
- if subscribed
25
- puts "Subscribed to mom (#{@mom_uri}). Listening at #{@subscriber_uri}"
26
- end
27
- end
28
-
29
- def start
30
- DRb.start_service(@subscriber_uri, self)
31
-
32
- mom = DRbObject.new(nil, @mom_uri)
33
- mom.subscribe @subscriber_uri
34
-
35
- DRb.thread.join # Don't exit just yet!
36
- end
37
-
38
- end
39
-
40
- end
41
-
42
- end
@@ -1,8 +0,0 @@
1
- require 'adaptation'
2
- require 'adaptation/mom'
3
-
4
- config = YAML::load(File.open("#{ADAPTOR_ROOT}/config/mom.yml"))
5
- mom_uri = "druby://#{config["mom"]["host"]}:#{config["mom"]["port"]}"
6
-
7
- mom = Adaptation::Mom.new mom_uri
8
- mom.start
@@ -1,25 +0,0 @@
1
- require 'adaptation'
2
-
3
- environment = "development" # TODO: "un-hardcode" this
4
- config = YAML::load(File.open("config/mom.yml"))["development"]
5
-
6
- case config["mom"]["type"]
7
- when "druby"
8
- require 'adaptation/druby_subscriber'
9
-
10
- mom_uri = "druby://#{config["mom"]["host"]}:#{config["mom"]["port"]}"
11
- subscriber_uri = "druby://#{config["subscriber"]["host"]}:#{config["subscriber"]["port"]}"
12
- topics = config["subscriber"]["topics"].split(' ')
13
-
14
- Signal.trap("INT") { puts "Shutting down subscriber (#{config["mom"]["type"]})"; exit }
15
-
16
- oapdaemon = Adaptation::Mom::DrubySubscriber.new subscriber_uri, mom_uri, topics
17
- oapdaemon.start
18
-
19
- #when "xmlblaster"
20
- #
21
-
22
- else
23
- puts "Unknown MOM server type: #{config["mom"]["type"]}"
24
- end
25
-
@@ -1,136 +0,0 @@
1
- require 'rbconfig'
2
-
3
- class AppGenerator < Rails::Generator::Base
4
- DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
5
- Config::CONFIG['ruby_install_name'])
6
-
7
- DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase)
8
-
9
- default_options :db => "mysql", :shebang => DEFAULT_SHEBANG, :freeze => false
10
- mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
11
-
12
- def initialize(runtime_args, runtime_options = {})
13
- super
14
- usage if args.empty?
15
- usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
16
- @destination_root = args.shift
17
- @app_name = File.basename(File.expand_path(@destination_root))
18
- end
19
-
20
- def manifest
21
- # Use /usr/bin/env if no special shebang was specified
22
- script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
23
- dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
24
-
25
- record do |m|
26
- # Root directory and all subdirectories.
27
- m.directory ''
28
- BASEDIRS.each { |path| m.directory path }
29
-
30
- # Root
31
- m.file "README", "README"
32
-
33
- # Application
34
- m.file "helpers/test_helper.rb", "test/test_helper.rb"
35
- m.file "helpers/publish.rb", "test/mocks/test/publish.rb"
36
-
37
- # database.yml
38
- m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
39
- :app_name => @app_name,
40
- :socket => options[:db] == "mysql" ? mysql_socket_location : nil
41
- }
42
-
43
- # mom.yml
44
- m.template "configs/mom.yml", "config/mom.yml"
45
-
46
- # settings.yml
47
- m.template "configs/settings.yml", "config/settings.yml"
48
-
49
- # boot.rb, needed by some scripts
50
- m.file "configs/boot.rb", "config/boot.rb"
51
-
52
- # Environments
53
- #m.file "environments/boot.rb", "config/boot.rb"
54
- #m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze] }
55
- #m.file "environments/production.rb", "config/environments/production.rb"
56
- #m.file "environments/development.rb", "config/environments/development.rb"
57
- #m.file "environments/test.rb", "config/environments/test.rb"
58
-
59
- # Scripts
60
- %w( generate destroy about subscribe ).each do |file|
61
- m.file "bin/#{file}", "script/#{file}", script_options
62
- end
63
-
64
- # Dispatches
65
- m.file "dispatches/dispatch.rb", "public/dispatch.rb", script_options
66
- m.file "dispatches/publish.rb", "public/publish.rb", script_options
67
-
68
- # Docs
69
- m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
70
-
71
- # Logs
72
- %w(server production development test).each { |file|
73
- m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
74
- }
75
- end
76
- end
77
-
78
- protected
79
- def banner
80
- "Usage: #{$0} /path/to/your/app [options]"
81
- end
82
-
83
- def add_options!(opt)
84
- opt.separator ''
85
- opt.separator 'Options:'
86
- opt.on("-r", "--ruby=path", String,
87
- "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
88
- "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v }
89
-
90
- opt.on("-d", "--database=name", String,
91
- "Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).",
92
- "Default: mysql") { |v| options[:db] = v }
93
-
94
- #opt.on("-f", "--freeze",
95
- # "Freeze Rails in vendor/rails from the gems generating the skeleton",
96
- # "Default: false") { |v| options[:freeze] = v }
97
- end
98
-
99
- def mysql_socket_location
100
- MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
101
- end
102
-
103
-
104
- # Installation skeleton. Intermediate directories are automatically
105
- # created so don't sweat their absence here.
106
- BASEDIRS = %w(
107
- app/adaptors
108
- app/messages
109
- app/models
110
- config/environments
111
- db
112
- doc
113
- lib
114
- lib/tasks
115
- log
116
- public
117
- script
118
- test/fixtures
119
- test/functional
120
- test/mocks/development
121
- test/mocks/test
122
- test/unit
123
- )
124
-
125
- MYSQL_SOCKET_LOCATIONS = [
126
- "/tmp/mysql.sock", # default
127
- "/var/run/mysqld/mysqld.sock", # debian/gentoo
128
- "/var/tmp/mysql.sock", # freebsd
129
- "/var/lib/mysql/mysql.sock", # fedora
130
- "/opt/local/lib/mysql/mysql.sock", # fedora
131
- "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
132
- "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
133
- "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
134
- "/opt/lampp/var/mysql/mysql.sock" # xampp for linux
135
- ]
136
- end