moodle2cc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module Moodle2CC::CC
7
7
 
8
8
  def initialize(mod)
9
9
  super
10
- @url = mod.reference
10
+ @url = mod.reference.to_s.strip
11
11
  end
12
12
 
13
13
  def self.create_resource_key(mod)
@@ -0,0 +1,19 @@
1
+ module Moodle2CC
2
+ class Logger
3
+ def self.logger
4
+ Thread.current[:__moodle2cc_logger__] || ::Logger.new(STDOUT)
5
+ end
6
+
7
+ def self.logger=(logger)
8
+ Thread.current[:__moodle2cc_logger__] = logger
9
+ end
10
+
11
+ def self.add_warning(message, exception)
12
+ if logger.respond_to? :add_warning
13
+ logger.add_warning(message, exception)
14
+ elsif logger.respond_to? :warn
15
+ logger.warn "#{message}\n #{exception.message}\n"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -4,6 +4,7 @@ module Moodle2CC
4
4
  @source = source
5
5
  @destination = destination
6
6
  @format = options['format'] || 'cc'
7
+ Moodle2CC::Logger.logger = options['logger'] || ::Logger.new(STDOUT)
7
8
  raise(Moodle2CC::Error, "'#{@source}' does not exist") unless File.exists?(@source)
8
9
  raise(Moodle2CC::Error, "'#{@destination}' is not a directory") unless File.directory?(@destination)
9
10
  raise(Moodle2CC::Error, "'#{@format}' is not a valid format. Please use 'cc' or 'canvas'.") unless ['cc', 'canvas'].include?(@format)
@@ -14,6 +15,8 @@ module Moodle2CC
14
15
  backup = Moodle2CC::Moodle::Backup.read @source
15
16
  @converter = @converter_class.new backup, @destination
16
17
  @converter.convert
18
+ rescue StandardError => error
19
+ Moodle2CC::Logger.add_warning 'error migrating content', error
17
20
  end
18
21
 
19
22
  def imscc_path
@@ -1,3 +1,3 @@
1
1
  module Moodle2CC
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/moodle2cc.rb CHANGED
@@ -1,13 +1,15 @@
1
- require 'uri'
1
+ require 'builder'
2
2
  require 'cgi'
3
- require 'ostruct'
4
- require 'fileutils'
5
3
  require 'erb'
4
+ require 'fileutils'
6
5
  require 'happymapper'
7
- require 'builder'
6
+ require 'logger'
8
7
  require 'nokogiri'
8
+ require 'ostruct'
9
+ require 'uri'
9
10
 
10
11
  require 'moodle2cc/error'
12
+ require 'moodle2cc/logger'
11
13
  require 'moodle2cc/migrator'
12
14
 
13
15
  module Moodle2CC
@@ -36,6 +36,13 @@ class TestUnitCCWebLink < MiniTest::Unit::TestCase
36
36
  assert_equal "http://en.wikipedia.org/wiki/Einstein", web_link.url
37
37
  end
38
38
 
39
+ def test_it_strips_whitespace_from_url
40
+ @mod.reference = " http://en.wikipedia.org/wiki/Einstein "
41
+
42
+ web_link = Moodle2CC::CC::WebLink.new @mod
43
+ assert_equal "http://en.wikipedia.org/wiki/Einstein", web_link.url
44
+ end
45
+
39
46
  def test_it_has_an_identifier
40
47
  @mod.id = 123
41
48
 
@@ -0,0 +1,33 @@
1
+ require 'minitest/autorun'
2
+ require 'moodle2cc'
3
+ require 'stringio'
4
+
5
+ class TestUnitLogger < MiniTest::Unit::TestCase
6
+ class MyLogger
7
+ attr_accessor :message, :exception
8
+
9
+ def add_warning(message, exception)
10
+ @message = message
11
+ @exception = exception
12
+ end
13
+ end
14
+
15
+ def test_it_logs_a_warning
16
+ stdout = StringIO.new
17
+ Moodle2CC::Logger.logger = ::Logger.new(stdout)
18
+ ex = StandardError.new 'Kablooey!!!'
19
+ Moodle2CC::Logger.add_warning 'got an error', ex
20
+ assert_match /got an error/, stdout.string
21
+ assert_match /Kablooey!!!/, stdout.string
22
+ end
23
+
24
+ def test_it_adds_a_warning
25
+ my_logger = MyLogger.new
26
+ Moodle2CC::Logger.logger = my_logger
27
+ ex = StandardError.new 'Kablooey!!!'
28
+ msg = 'got an error'
29
+ Moodle2CC::Logger.add_warning msg, ex
30
+ assert_equal msg, my_logger.message
31
+ assert_equal ex, my_logger.exception
32
+ end
33
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moodle2cc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Durtschi
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-07-24 00:00:00 Z
20
+ date: 2012-07-26 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rubyzip
@@ -213,6 +213,7 @@ files:
213
213
  - lib/moodle2cc/cc/wiki.rb
214
214
  - lib/moodle2cc/cli.rb
215
215
  - lib/moodle2cc/error.rb
216
+ - lib/moodle2cc/logger.rb
216
217
  - lib/moodle2cc/migrator.rb
217
218
  - lib/moodle2cc/moodle/backup.rb
218
219
  - lib/moodle2cc/moodle/course.rb
@@ -256,6 +257,7 @@ files:
256
257
  - test/unit/cc/web_content_test.rb
257
258
  - test/unit/cc/web_link_test.rb
258
259
  - test/unit/cc/wiki_test.rb
260
+ - test/unit/logger_test.rb
259
261
  - test/unit/migrator_test.rb
260
262
  - test/unit/moodle/backup_test.rb
261
263
  - test/unit/moodle/course_test.rb
@@ -331,6 +333,7 @@ test_files:
331
333
  - test/unit/cc/web_content_test.rb
332
334
  - test/unit/cc/web_link_test.rb
333
335
  - test/unit/cc/wiki_test.rb
336
+ - test/unit/logger_test.rb
334
337
  - test/unit/migrator_test.rb
335
338
  - test/unit/moodle/backup_test.rb
336
339
  - test/unit/moodle/course_test.rb