aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/command.rb
diff options
context:
space:
mode:
authorcedricnjanga2017-11-21 15:32:22 +0100
committercedricnjanga2017-11-21 15:32:22 +0100
commit763010ced3202c99f705562a373861f926aad9a1 (patch)
treea316366c92fcf9c88aa8d08ff34e0b737196d618 /app/models/chouette/command.rb
parent80bfa87237b78e426e4362a503fe4d72e130beb5 (diff)
downloadchouette-core-763010ced3202c99f705562a373861f926aad9a1.tar.bz2
Change the way we name classes
We now always use modules for namespaces => same structure for models, decorators, policies...
Diffstat (limited to 'app/models/chouette/command.rb')
-rw-r--r--app/models/chouette/command.rb120
1 files changed, 60 insertions, 60 deletions
diff --git a/app/models/chouette/command.rb b/app/models/chouette/command.rb
index d2995a000..b735747bf 100644
--- a/app/models/chouette/command.rb
+++ b/app/models/chouette/command.rb
@@ -10,85 +10,85 @@ require 'tmpdir'
end
#end
-class Chouette::Command
+module Chouette
+ class Command
- include Chouette::CommandLineSupport
+ include Chouette::CommandLineSupport
- @@command = "chouette"
- cattr_accessor :command
+ @@command = "chouette"
+ cattr_accessor :command
- attr_accessor :database, :schema, :host, :user, :password, :port
+ attr_accessor :database, :schema, :host, :user, :password, :port
- def initialize(options = {})
- database_options_from_active_record.merge(options).each do |k,v|
- send "#{k}=", v
+ def initialize(options = {})
+ database_options_from_active_record.merge(options).each do |k,v|
+ send "#{k}=", v
+ end
end
- end
- def database_options_from_active_record
- config = Chouette::ActiveRecord.connection_pool.spec.config
- {
- :database => config[:database],
- :user => config[:username],
- :password => config[:password],
- :port => config[:port],
- :host => (config[:host] or "localhost")
- }
- end
+ def database_options_from_active_record
+ config = Chouette::ActiveRecord.connection_pool.spec.config
+ {
+ :database => config[:database],
+ :user => config[:username],
+ :password => config[:password],
+ :port => config[:port],
+ :host => (config[:host] or "localhost")
+ }
+ end
- def run!(options = {})
- Dir.mktmpdir do |config_dir|
- chouette_properties = File.join(config_dir, "chouette.properties")
- open(chouette_properties, "w") do |f|
- f.puts "database.name = #{database}"
- f.puts "database.schema = #{schema}"
- #f.puts "database.showsql = true"
- f.puts "hibernate.username = #{user}"
- f.puts "hibernate.password = #{password}"
- f.puts "jdbc.url=jdbc:postgresql://#{host}:#{port}/#{database}"
- f.puts "jdbc.username = #{user}"
- f.puts "jdbc.password = #{password}"
- #f.puts "database.hbm2ddl.auto=update"
- end
+ def run!(options = {})
+ Dir.mktmpdir do |config_dir|
+ chouette_properties = File.join(config_dir, "chouette.properties")
+ open(chouette_properties, "w") do |f|
+ f.puts "database.name = #{database}"
+ f.puts "database.schema = #{schema}"
+ #f.puts "database.showsql = true"
+ f.puts "hibernate.username = #{user}"
+ f.puts "hibernate.password = #{password}"
+ f.puts "jdbc.url=jdbc:postgresql://#{host}:#{port}/#{database}"
+ f.puts "jdbc.username = #{user}"
+ f.puts "jdbc.password = #{password}"
+ #f.puts "database.hbm2ddl.auto=update"
+ end
- logger.debug "Chouette properties: #{File.readlines(chouette_properties).collect(&:strip).join(', ')}"
+ logger.debug "Chouette properties: #{File.readlines(chouette_properties).collect(&:strip).join(', ')}"
- command_line = "#{command} -classpath #{config_dir} #{command_options(options)}"
- logger.debug "Execute '#{command_line}'"
+ command_line = "#{command} -classpath #{config_dir} #{command_options(options)}"
+ logger.debug "Execute '#{command_line}'"
- execute! command_line
+ execute! command_line
+ end
end
- end
- class Option
+ class Option
- attr_accessor :key, :value
+ attr_accessor :key, :value
- def initialize(key, value)
- @key, @value = key.to_s, value
- end
+ def initialize(key, value)
+ @key, @value = key.to_s, value
+ end
- def command_key
- key.camelize(:lower)
- end
+ def command_key
+ key.camelize(:lower)
+ end
- def to_s
- unless value == true
- "-#{command_key} #{value}"
- else
- "-#{command_key}"
+ def to_s
+ unless value == true
+ "-#{command_key} #{value}"
+ else
+ "-#{command_key}"
+ end
end
+
end
- end
+ def command_options(options)
+ options.collect do |key, value|
+ Option.new(key, value)
+ end.sort_by(&:key).join(' ')
+ end
- def command_options(options)
- options.collect do |key, value|
- Option.new(key, value)
- end.sort_by(&:key).join(' ')
end
-
-
-
-end
+end \ No newline at end of file