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

Public Instance methods

[Source]

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

[Validate]