Class: SchemaRD::Configuration

Inherits:
Struct
  • Object
show all
Includes:
Utils::StructAssigner
Defined in:
lib/schemard/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StructAssigner

#assign

Constructor Details

#initialize(argv = nil) ⇒ Configuration

Returns a new instance of Configuration.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# 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

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



98
99
100
# File 'lib/schemard/controller.rb', line 98

def errors
  @errors
end

Instance Method Details

#parse_db_comment?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/schemard/controller.rb', line 120

def parse_db_comment?
  self.parse_db_comment_as != "ignore"
end

#valid?Boolean

Returns:

  • (Boolean)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# 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..each do ||
    unless File.readable?()
      self.errors << "MetadataFile: \"#{}\" 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