Class MediaWiki::Config
In: lib/media_wiki/config.rb
Parent: Object

Methods

abort   new  

Attributes

article  [R] 
desc  [R] 
file  [R] 
pw  [R] 
summary  [R] 
target  [R] 
url  [R] 
user  [R] 

Public Class methods

[Source]

    # File lib/media_wiki/config.rb, line 10
10:     def initialize(args, type = "read")
11:       @summary = "Automated edit via MediaWiki::Gateway"
12:       @opts = OptionParser.new do |opts|
13:         opts.banner = "Usage: [options]"
14:         
15:         opts.on("-h", "--host HOST", "Use preconfigured HOST in config/hosts.yml") do |host_id|
16:           yaml = YAML.load_file('config/hosts.yml')
17:           if yaml.include? host_id
18:             host = yaml[host_id]
19:             @url = host['url']
20:             @pw = host['pw']
21:             @user = host['user']
22:           else
23:             raise "Host #{host_id} not found in config/hosts.yml"
24:           end
25:         end
26: 
27:         if type == "upload"
28:           opts.on("-d", "--description DESCRIPTION", "Description of file to upload") do |desc|
29:             @desc = desc
30:           end
31:           opts.on("-t", "--target-file TARGET-FILE", "Target file name to upload to") do |target|
32:             @target = target
33:           end
34:         else
35:           opts.on("-a", "--article ARTICLE", "Name of article in Wiki") do |article|
36:             @article = article
37:           end
38:         end
39:         
40:         opts.on("-n", "--username USERNAME", "Username for login") do |user|
41:           @user = user
42:         end
43: 
44:         opts.on("-p", "--password PASSWORD", "Password for login") do |pw|
45:           @pw = pw
46:         end
47: 
48:         if type != "read"
49:           opts.on("-s", "--summary SUMMARY", "Edit summary for this change") do |summary|
50:             @summary = summary
51:           end
52:         end
53: 
54:         opts.on("-u", "--url URL", "MediaWiki API URL") do |url|
55:           @url = url
56:         end
57:       end
58:       @opts.parse!
59:       abort("URL (-u) or valid host (-h) is mandatory.") unless @url
60:     end

Public Instance methods

[Source]

    # File lib/media_wiki/config.rb, line 62
62:     def abort(error)
63:       puts "Error: #{error}\n\n#{@opts.to_s}"
64:       exit
65:     end

[Validate]