module MediaWiki::TestWiki::RakeHelper
Public Instance Methods
broken_version?(strict = false)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 202 def broken_version?(strict = false) verified_version?(strict, config.broken_versions) end
configure(base, load_tasks = false, &block)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 52 def configure(base, load_tasks = false, &block) Config.enhance(base, &block).tap { require_relative 'rake_tasks' if load_tasks } end
docker_tasks(name, image)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 60 def docker_tasks(name, image) %w[start stop restart clean clobber].each { |task| task(task) { send("docker_#{task}", name, image) } } task(:start) { puts "#{name}: #{docker_url(name)}" } end
extended(base)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 39 def extended(base) keep = [:noop, :verbose] base.define_singleton_method(:docker_system) { |*args, &block| options = !args.last.is_a?(Hash) ? {} : args.pop.keep_if { |k,| keep.include?(k) } sh(*args << options, &block) } configure(base) unless base.respond_to?(:config) end
file_size(*args) { |self| ... }
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 68 def file_size(*args) file_create(*args) { |t| File.write(t.name, '') }.instance_eval { def needed?; !File.size?(name); end yield self if block_given? self } end
fix_config(file, host)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 76 def fix_config(file, host) File.write(file, File.read(file).tap { |content| content.sub!(/^\$wgServer\b/, '#\&') content.gsub!(host, 'localhost') }) end
needed?()
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 70 def needed?; !File.size?(name); end
setup_broken(arg)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 83 def setup_broken(arg) msg = <<-EOT *** Manual configuration is broken for this MediaWiki version. *** EOT if arg.is_a?(LoadError) abort msg << <<-EOT However, automatic configuration is not available: #{arg}. Please install the `mechanize' gem and try again. EOT elsif arg wait msg << <<-EOT Also, automatic configuration is not supported for this version either. Please create a valid configuration file and press enter when finished: #{arg} EOT else abort msg << <<-EOT However, you have requested to skip automatic configuration. Please unset `NOMECHANIZE' and try again. EOT end end
setup_manual(url, dir, cfg, err = nil, unk = nil)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 109 def setup_manual(url, dir, cfg, err = nil, unk = nil) msg = <<-EOT Visit #{url} and configure the wiki: EOT msg << " NOTE: These configuration instructions have not been verified for this version of MediaWiki -- please use your own judgement! " if unk msg << <<-EOT - Language - Continue - Welcome to MediaWiki! - Continue - Connect to database - Database type: SQLite - SQLite data directory: #{dir} - Database name: #{config.database_name} - Continue - Name - Name of wiki: #{config.sitename} - Your username: #{config.username} - Password: #{config.password} - Password again: #{config.password} - I'm bored already, just install the wiki. - Continue - Install (1) - Continue - Install (2) - Continue Save #{File.basename(cfg)} (replace existing file if already present): #{cfg} Close configuration window and press enter when finished. EOT msg << " NOTE: Install the `mechanize' gem to automate this process. (#{err}) " if err wait(msg) end
setup_mechanize(url, dir, cfg)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 163 def setup_mechanize(url, dir, cfg) agent = Mechanize.new page = agent.get(url) continue = lambda { |&block| form = page.forms.first block[form] if block page = agent.submit(form) } 2.times { continue.() } continue.() { |form| form.sqlite_wgSQLiteDataDir = dir form.sqlite_wgDBname = config.database_name form.radiobuttons_with(value: 'sqlite').first.check } continue.() { |form| form.radiobuttons_with(value: 'skip').first.check form.config_wgSitename = config.sitename form.config__AdminName = config.username form.config__AdminPassword = config.password form.config__AdminPassword2 = config.password } 2.times { continue.() } page.link_with(text: Regexp.new( Regexp.escape(File.basename(cfg)))).click.save!(cfg) end
verified_version?(strict = false, list = config.verified_versions)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 197 def verified_version?(strict = false, list = config.verified_versions) strict ? list.include?(config.version) : list.grep(/\A#{Regexp.escape(config.version[/.*\./])}/).any? end
Private Instance Methods
wait(msg)
click to toggle source
# File lib/media_wiki/test_wiki/rake_helper.rb, line 208 def wait(msg) puts(msg) $stdin.gets end