aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette/file_validator.rb
blob: 98453c71c8a95b5fe57c318651e7850ebbb7fe69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Chouette
  class FileValidator

    attr_reader :schema, :database, :user, :password, :host

    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

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

    class << self
      deprecate :chouette_command= => "Use Chouette::Command.command ="
    end

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

    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


    include Chouette::CommandLineSupport

  end
end