Class: Source
- Inherits:
-
SourceBase
- Object
- SourceBase
- Source
- Defined in:
- lib/abelard/load.rb
Instance Method Summary collapse
- #all_configs ⇒ Object
- #get_config(key) ⇒ Object
-
#initialize(conf_in) ⇒ Source
constructor
A new instance of Source.
- #load ⇒ Object
- #save_config(key, conf) ⇒ Object
- #write_raw(data, filename) ⇒ Object
Methods inherited from SourceBase
Constructor Details
Instance Method Details
#all_configs ⇒ Object
258 259 260 |
# File 'lib/abelard/load.rb', line 258 def all_configs YAML.load_file(CONFIG_FILE) || {} end |
#get_config(key) ⇒ Object
262 263 264 265 |
# File 'lib/abelard/load.rb', line 262 def get_config(key) configuration_file = all_configs configuration_file[key] end |
#load ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/abelard/load.rb', line 237 def load conf = @conf dest = conf["dest"] || die("No 'dest' directory defined") urls = conf["urls"] || die("No urls defined") ensure_dest(dest) fetcher = Fetcher.new fetcher.user = conf["user"] fetcher.password = conf["password"] urls.each do |urlpath| url = URI(urlpath) fetcher.get(url) do |response| write_raw(response.body, "#{dest}/raw.xml") if Debug parser = LibXML::XML::Parser.string(response.body) process(parser, dest) end end end |
#save_config(key, conf) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/abelard/load.rb', line 267 def save_config(key, conf) configuration_data = all_configs if configuration_data.has_key? key die("Already have config for #{key}") else configuration_data[key] = conf open(CONFIG_FILE, 'w+') do |conf_file| conf_file.puts(configuration_data.to_yaml) end end end |
#write_raw(data, filename) ⇒ Object
279 280 281 |
# File 'lib/abelard/load.rb', line 279 def write_raw(data, filename) File.open(filename, "w") { |f| f.write(data) } end |