class SchemaRD::Configuration
Attributes
errors[R]
Public Class Methods
new(argv = nil)
click to toggle source
# File lib/schemard/controller.rb, line 99 def initialize(argv = nil) hash = {}.merge(DEFAULT_CONFIG) hash.merge!(YAML.load_file(CONFIG_FILE)) if File.readable?(CONFIG_FILE) unless argv.nil? opt = OptionParser.new opt.on('-i VAL', '--input-file=VAL') {|v| hash[:input_file] = v } opt.on('-o VAL', '--output-file=VAL') {|v| hash[:output_file] = v } opt.on('-f VAL', '-m VAL', '--metadata-file=VAL') {|v| hash[:metadata_files] << v } opt.on('--rdoc', '--rdoc-enabled') { hash[:rdoc_enabled] = true } opt.on('--parse-db-comment-as=VAL') {|v| hash[:parse_db_comment_as] = v } opt.on('-s', '--silent', '--no-log-output') {|v| hash[:log_output] = File.open(File::NULL, 'w') } opt.on('-h VAL', '--host=VAL') {|v| hash[:webserver_host] = v } opt.on('-p VAL', '--port=VAL') {|v| hash[:webserver_port] = v } opt.on('-l VAL', '--log-output=VAL') {|v| hash[:log_output] = self.class.str_to_io(v) } opt.on('-v', '--version') {|v| hash[:show_version] = true } opt.parse(argv) end self.assign(hash) end
Private Class Methods
str_to_io(str)
click to toggle source
# File lib/schemard/controller.rb, line 154 def self.str_to_io(str) case str when "stdout", "STDOUT" STDOUT when "stderr", "STDERR" STDERR else File.open(str, 'w') rescue str end end
Public Instance Methods
parse_db_comment?()
click to toggle source
# File lib/schemard/controller.rb, line 120 def parse_db_comment? self.parse_db_comment_as != "ignore" end
valid?()
click to toggle source
# File lib/schemard/controller.rb, line 124 def valid? @errors = [] unless File.readable?(self.input_file) self.errors << "InputFile: \"#{self.input_file}\" is not readable!" end unless (File.writable?(self.output_file) || File.writable?(File.dirname(self.output_file))) self.errors << "OutputFile: \"#{self.output_file}\" is not writable!" end self.metadata_files.each do |metadata_file| unless File.readable?(metadata_file) self.errors << "MetadataFile: \"#{metadata_file}\" is not readable!" end end unless %w(ignore name localized_name description custom).include?(self.parse_db_comment_as) self.errors << "ParseDBCommentAs: \"#{self.parse_db_comment_as}\" is not allowed!" end if self.log_output.is_a?(String) self.errors << "LogFile: \"#{self.log_output}\" is not writable!" end unless self.webserver_port =~ /^[0-9]+$/ self.errors << "WebServerPort: \"#{self.webserver_port}\" is invalid!" end if self.show_version self.errors << "schemard: version-#{SchemaRD::VERSION}" end self.errors.empty? end