Module: MediaWiki::TestWiki::RakeHelper

Includes:
DockerHelper
Defined in:
lib/media_wiki/test_wiki/rake_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DockerHelper

docker, #docker_build, #docker_container_name, #docker_image_name, #docker_url, #docker_volume

Class Method Details

.configure(base, load_tasks = false, &block) ⇒ Object



52
53
54
55
56
# 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

.extended(base) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# 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

Instance Method Details

#broken_version?(strict = false) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/media_wiki/test_wiki/rake_helper.rb', line 202

def broken_version?(strict = false)
  verified_version?(strict, config.broken_versions)
end

#docker_tasks(name, image) ⇒ Object



60
61
62
63
64
65
66
# 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

#file_size(*args) ⇒ Object



68
69
70
71
72
73
74
# 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) ⇒ Object



76
77
78
79
80
81
# 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

#setup_broken(arg) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
151
152
153
154
155
156
157
158
159
160
161
# 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 << <<-EOT if unk

NOTE: These configuration instructions have not been verified for
this version of MediaWiki -- please use your own judgement!
  EOT

  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 << <<-EOT if err

NOTE: Install the `mechanize' gem to automate this process. (#{err})
  EOT

  wait(msg)
end

#setup_mechanize(url, dir, cfg) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# 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) ⇒ Boolean

Returns:

  • (Boolean)


197
198
199
200
# 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