Class: Chouette::FileValidator

Inherits:
Object
  • Object
show all
Includes:
CommandLineSupport
Defined in:
app/models/chouette/file_validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommandLineSupport

#available_loggers, #execute!, #logger, #max_output_length

Constructor Details

#initialize(schema) ⇒ FileValidator

Returns a new instance of FileValidator.



5
6
7
8
9
10
11
12
13
14
# File 'app/models/chouette/file_validator.rb', line 5

def initialize(schema)
  @schema = schema

  Chouette::ActiveRecord.connection_pool.spec.config.tap do |config|
    @database = config[:database]
    @user = config[:username]
    @password = config[:password]
    @host = (config[:host] or "localhost")
  end
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



3
4
5
# File 'app/models/chouette/file_validator.rb', line 3

def database
  @database
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'app/models/chouette/file_validator.rb', line 3

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



3
4
5
# File 'app/models/chouette/file_validator.rb', line 3

def password
  @password
end

#schemaObject (readonly)

Returns the value of attribute schema.



3
4
5
# File 'app/models/chouette/file_validator.rb', line 3

def schema
  @schema
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'app/models/chouette/file_validator.rb', line 3

def user
  @user
end

Class Method Details

.chouette_command=(command) ⇒ Object



16
17
18
# File 'app/models/chouette/file_validator.rb', line 16

def self.chouette_command=(command)
  Chouette::Command.command = command
end

Instance Method Details

#chouette_commandObject



24
25
26
# File 'app/models/chouette/file_validator.rb', line 24

def chouette_command
  @chouette_command ||= Chouette::Command.new(:schema => schema)
end

#validate(file, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/chouette/file_validator.rb', line 28

def validate(file, options = {})
  options = {
    :format => :neptune
  }.merge(options)

  command_options = {
    :c => "validate", 
    :o => "line", 
    :input_file => File.expand_path(file), 
    :optimize_memory => true
  }.merge(options)

  logger.info "Validate #{file}"
  chouette_command.run! command_options
end