Class: Chouette::Command
- Inherits:
-
Object
- Object
- Chouette::Command
- Includes:
- CommandLineSupport
- Defined in:
- app/models/chouette/command.rb
Overview
end
Defined Under Namespace
Classes: Option
Constant Summary collapse
- @@command =
"chouette"
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #command_options(options) ⇒ Object
- #database_options_from_active_record ⇒ Object
-
#initialize(options = {}) ⇒ Command
constructor
A new instance of Command.
- #run!(options = {}) ⇒ Object
Methods included from CommandLineSupport
#available_loggers, #execute!, #logger, #max_output_length
Constructor Details
#initialize(options = {}) ⇒ Command
Returns a new instance of Command.
22 23 24 25 26 |
# File 'app/models/chouette/command.rb', line 22 def initialize( = {}) .merge().each do |k,v| send "#{k}=", v end end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
20 21 22 |
# File 'app/models/chouette/command.rb', line 20 def database @database end |
#host ⇒ Object
Returns the value of attribute host.
20 21 22 |
# File 'app/models/chouette/command.rb', line 20 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
20 21 22 |
# File 'app/models/chouette/command.rb', line 20 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
20 21 22 |
# File 'app/models/chouette/command.rb', line 20 def port @port end |
#schema ⇒ Object
Returns the value of attribute schema.
20 21 22 |
# File 'app/models/chouette/command.rb', line 20 def schema @schema end |
#user ⇒ Object
Returns the value of attribute user.
20 21 22 |
# File 'app/models/chouette/command.rb', line 20 def user @user end |
Instance Method Details
#command_options(options) ⇒ Object
86 87 88 89 90 |
# File 'app/models/chouette/command.rb', line 86 def () .collect do |key, value| Option.new(key, value) end.sort_by(&:key).join(' ') end |
#database_options_from_active_record ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/chouette/command.rb', line 28 def 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 |
#run!(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/chouette/command.rb', line 40 def run!( = {}) 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(', ')}" command_line = "#{command} -classpath #{config_dir} #{command_options(options)}" logger.debug "Execute '#{command_line}'" execute! command_line end end |