daigaku 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/README.md +25 -3
  4. data/Rakefile +3 -0
  5. data/daigaku.gemspec +3 -2
  6. data/lib/daigaku/configuration.rb +7 -4
  7. data/lib/daigaku/congratulator.rb +13 -0
  8. data/lib/daigaku/course.rb +5 -0
  9. data/lib/daigaku/generator.rb +13 -6
  10. data/lib/daigaku/github_client.rb +30 -0
  11. data/lib/daigaku/reference_solution.rb +10 -2
  12. data/lib/daigaku/solution.rb +19 -8
  13. data/lib/daigaku/storeable.rb +32 -0
  14. data/lib/daigaku/terminal/courses.rb +103 -11
  15. data/lib/daigaku/terminal/output.rb +6 -0
  16. data/lib/daigaku/terminal/texts/congratulations.txt +12 -0
  17. data/lib/daigaku/terminal.rb +2 -1
  18. data/lib/daigaku/test_result.rb +5 -3
  19. data/lib/daigaku/version.rb +1 -1
  20. data/lib/daigaku/views/chapters_menu.rb +19 -50
  21. data/lib/daigaku/views/courses_menu.rb +14 -49
  22. data/lib/daigaku/views/main_menu.rb +6 -6
  23. data/lib/daigaku/views/menu.rb +89 -0
  24. data/lib/daigaku/views/task_view.rb +29 -11
  25. data/lib/daigaku/views/top_bar.rb +9 -17
  26. data/lib/daigaku/views/units_menu.rb +21 -52
  27. data/lib/daigaku/views.rb +4 -12
  28. data/lib/daigaku/window.rb +46 -3
  29. data/lib/daigaku.rb +1 -4
  30. data/spec/daigaku/configuration_spec.rb +11 -11
  31. data/spec/daigaku/congratulator_spec.rb +24 -0
  32. data/spec/daigaku/course_spec.rb +18 -0
  33. data/spec/daigaku/generator_spec.rb +4 -4
  34. data/spec/daigaku/github_client_spec.rb +53 -0
  35. data/spec/daigaku/reference_solution_spec.rb +20 -2
  36. data/spec/daigaku/solution_spec.rb +13 -6
  37. data/spec/daigaku/storeable_spec.rb +35 -0
  38. data/spec/daigaku/terminal/courses_spec.rb +215 -5
  39. data/spec/daigaku/terminal/output_spec.rb +31 -3
  40. data/spec/daigaku/terminal_spec.rb +12 -2
  41. data/spec/daigaku/test_result_spec.rb +12 -2
  42. data/spec/daigaku/views/chapters_menu_spec.rb +1 -3
  43. data/spec/daigaku/views/courses_menu_spec.rb +1 -3
  44. data/spec/daigaku/views/menu_spec.rb +19 -0
  45. data/spec/daigaku/views/task_view_spec.rb +1 -1
  46. data/spec/daigaku/views/units_menu_spec.rb +1 -3
  47. data/spec/daigaku/views_spec.rb +0 -2
  48. data/spec/daigaku_spec.rb +0 -6
  49. data/spec/support/macros/content_helpers.rb +1 -1
  50. data/spec/support/macros/mock_helpers.rb +6 -1
  51. data/spec/support/macros/path_helpers.rb +12 -6
  52. data/spec/support/macros/resource_helpers.rb +3 -1
  53. metadata +33 -8
  54. data/lib/daigaku/database.rb +0 -64
  55. data/spec/daigaku/database_spec.rb +0 -79
@@ -2,7 +2,5 @@ require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Views::ChaptersMenu, type: :view do
4
4
 
5
- it { is_expected.to respond_to :enter_chapters_menu }
6
- it { is_expected.to respond_to :reenter_chapters_menu }
7
-
5
+ it { is_expected.to be_a Daigaku::Views::Menu }
8
6
  end
@@ -2,7 +2,5 @@ require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Views::CoursesMenu, type: :view do
4
4
 
5
- it { is_expected.to respond_to :enter }
6
- it { is_expected.to respond_to :reenter_courses_menu }
7
-
5
+ it { is_expected.to be_a Daigaku::Views::Menu }
8
6
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daigaku::Views::Menu do
4
+
5
+ it { is_expected.to respond_to :enter }
6
+ it { is_expected.to respond_to :reenter }
7
+
8
+ [
9
+ :show,
10
+ :draw,
11
+ :interact_with,
12
+ :models,
13
+ :items
14
+ ].each do |method|
15
+ it "has a protected method ##{method}" do
16
+ expect(subject.protected_methods).to include(method)
17
+ end
18
+ end
19
+ end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Views::TaskView, type: :view do
4
4
 
5
- it { is_expected.to respond_to :enter_task_view }
5
+ it { is_expected.to respond_to :enter }
6
6
 
7
7
  end
@@ -2,7 +2,5 @@ require 'spec_helper'
2
2
 
3
3
  describe Daigaku::Views::UnitsMenu, type: :view do
4
4
 
5
- it { is_expected.to respond_to :enter_units_menu }
6
- it { is_expected.to respond_to :reenter_units_menu }
7
-
5
+ it { is_expected.to be_a Daigaku::Views::Menu }
8
6
  end
@@ -12,8 +12,6 @@ describe Daigaku::Views do
12
12
 
13
13
  [
14
14
  :default_window,
15
- :top_bar,
16
- :main_panel,
17
15
  :sub_window_below_top_bar
18
16
  ].each do |method|
19
17
  it "has a private method ::#{method}" do
data/spec/daigaku_spec.rb CHANGED
@@ -48,10 +48,4 @@ describe "Daigaku module" do
48
48
  expect(Daigaku.config.solutions_path).to eq courses_basepath
49
49
  end
50
50
  end
51
-
52
- describe "::database" do
53
- it "returns a Diagaku::Database instance" do
54
- expect(Daigaku.database).to be_a Daigaku::Database
55
- end
56
- end
57
51
  end
@@ -87,7 +87,7 @@ module ContentHelpers
87
87
  }
88
88
  #
89
89
 
90
- TEST_PASSED_MESSAGE = "Your code passed all tests. Congratulations!"
90
+ TEST_PASSED_MESSAGE = "Your code passed all tests."
91
91
  EXAMPLE_PASSED_MESSAGE = "Your code passed this requirement."
92
92
 
93
93
  def task_file_content
@@ -7,7 +7,12 @@ module MockHelpers
7
7
  def use_test_storage_file
8
8
  Daigaku::Configuration.send(:new)
9
9
  Daigaku.config.instance_variable_set(:@storage_file, local_storage_file)
10
- Daigaku::Database.send(:new)
10
+
11
+ QuickStore.configure do |config|
12
+ config.file_path = Daigaku.config.storage_file
13
+ end
14
+
15
+ QuickStore.store.send(:new)
11
16
  end
12
17
 
13
18
  def suppress_print_out
@@ -5,8 +5,8 @@ module PathHelpers
5
5
  SOLUTIONS = 'solutions'
6
6
  TEMP_PATH = File.expand_path("../../../../tmp/", __FILE__)
7
7
  COURSE_DIR_NAMES = ['Course_A', 'Course_B']
8
- CHAPTER_DIR_NAMES = ['Chapter-1', 'Chapter-2']
9
- UNIT_DIR_NAMES = ['unit-1', 'unit-2']
8
+ CHAPTER_DIR_NAMES = ['1_Chapter-A', '2_Chapter-B']
9
+ UNIT_DIR_NAMES = ['1_unit-a', '2_unit-b']
10
10
  TASK_NAME = 'task.md'
11
11
  REFERENCE_SOLUTION_NAME = 'solution.rb'
12
12
  TEST_NAME = 'solution_spec.rb'
@@ -45,7 +45,7 @@ module PathHelpers
45
45
  end
46
46
 
47
47
  def courses_basepath
48
- File.join(test_basepath, COURSES)
48
+ File.join(test_basepath, LOCAL_DIR, COURSES)
49
49
  end
50
50
 
51
51
  def solutions_basepath
@@ -86,11 +86,17 @@ module PathHelpers
86
86
 
87
87
  def all_solution_file_paths
88
88
  all_unit_dirs.map do |unit_dir|
89
- underscored_unit_dir = File.basename(unit_dir).gsub(/(\_+|\-+|\.+)/, '_')
90
- file_name = underscored_unit_dir + Daigaku::Generator::SOLUTION_SUFFIX
89
+ underscored_unit_dir = File.basename(unit_dir).gsub(/[\_\-\.]+/, '_')
90
+ file_name = underscored_unit_dir + Daigaku::Solution::FILE_SUFFIX
91
+
91
92
  unit_path = File.join(solutions_basepath, unit_dir.split('/')[-3..-1])
93
+ parts = File.join(File.dirname(unit_path), file_name).split('/')
94
+
95
+ course_parts = parts[-3..-1].map do |part|
96
+ part.gsub(/^[\d]+\_/, '').gsub(/[\_\-]+/, '_').downcase
97
+ end
92
98
 
93
- File.join(File.dirname(unit_path), file_name)
99
+ [*parts[0...-3], *course_parts].join('/')
94
100
  end
95
101
  end
96
102
 
@@ -33,7 +33,9 @@ module ResourceHelpers
33
33
 
34
34
  Zip::File.open(zip_file_path, Zip::File::CREATE) do |zip_file|
35
35
  Dir[File.join(directory, '**', '**')].each do |file|
36
- zip_file.add(file.sub(directory, '')[1..-1], file) { true }
36
+ if file.match(course_dir_names.first)
37
+ zip_file.add(file.sub(directory, '')[1..-1], file) { true }
38
+ end
37
39
  end
38
40
  end
39
41
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daigaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Götze
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -152,6 +152,20 @@ dependencies:
152
152
  - - "<"
153
153
  - !ruby/object:Gem::Version
154
154
  version: '3.0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: quick_store
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: 0.1.0
162
+ type: :runtime
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: 0.1.0
155
169
  - !ruby/object:Gem::Dependency
156
170
  name: bundler
157
171
  requirement: !ruby/object:Gem::Requirement
@@ -209,7 +223,7 @@ dependencies:
209
223
  - !ruby/object:Gem::Version
210
224
  version: 4.5.0
211
225
  description: Daigaku is the Japanese word for university. With Daigaku you can interactively
212
- learn the Ruby Programming language using the command line.
226
+ learn the Ruby programming language using the command line.
213
227
  email:
214
228
  - paul.christoph.goetze@gmail.com
215
229
  executables:
@@ -218,6 +232,7 @@ extensions: []
218
232
  extra_rdoc_files: []
219
233
  files:
220
234
  - ".gitignore"
235
+ - ".travis.yml"
221
236
  - Gemfile
222
237
  - Guardfile
223
238
  - README.md
@@ -227,16 +242,18 @@ files:
227
242
  - lib/daigaku.rb
228
243
  - lib/daigaku/chapter.rb
229
244
  - lib/daigaku/configuration.rb
245
+ - lib/daigaku/congratulator.rb
230
246
  - lib/daigaku/course.rb
231
- - lib/daigaku/database.rb
232
247
  - lib/daigaku/exceptions.rb
233
248
  - lib/daigaku/generator.rb
249
+ - lib/daigaku/github_client.rb
234
250
  - lib/daigaku/loadable.rb
235
251
  - lib/daigaku/loading/chapters.rb
236
252
  - lib/daigaku/loading/courses.rb
237
253
  - lib/daigaku/loading/units.rb
238
254
  - lib/daigaku/reference_solution.rb
239
255
  - lib/daigaku/solution.rb
256
+ - lib/daigaku/storeable.rb
240
257
  - lib/daigaku/task.rb
241
258
  - lib/daigaku/terminal.rb
242
259
  - lib/daigaku/terminal/cli.rb
@@ -245,6 +262,7 @@ files:
245
262
  - lib/daigaku/terminal/setup.rb
246
263
  - lib/daigaku/terminal/solutions.rb
247
264
  - lib/daigaku/terminal/texts/about.txt
265
+ - lib/daigaku/terminal/texts/congratulations.txt
248
266
  - lib/daigaku/terminal/texts/courses_empty.txt
249
267
  - lib/daigaku/terminal/texts/hint_course_download.txt
250
268
  - lib/daigaku/terminal/texts/welcome.txt
@@ -257,6 +275,7 @@ files:
257
275
  - lib/daigaku/views/chapters_menu.rb
258
276
  - lib/daigaku/views/courses_menu.rb
259
277
  - lib/daigaku/views/main_menu.rb
278
+ - lib/daigaku/views/menu.rb
260
279
  - lib/daigaku/views/splash.rb
261
280
  - lib/daigaku/views/task_view.rb
262
281
  - lib/daigaku/views/top_bar.rb
@@ -264,14 +283,16 @@ files:
264
283
  - lib/daigaku/window.rb
265
284
  - spec/daigaku/chapter_spec.rb
266
285
  - spec/daigaku/configuration_spec.rb
286
+ - spec/daigaku/congratulator_spec.rb
267
287
  - spec/daigaku/course_spec.rb
268
- - spec/daigaku/database_spec.rb
269
288
  - spec/daigaku/generator_spec.rb
289
+ - spec/daigaku/github_client_spec.rb
270
290
  - spec/daigaku/loading/chapters_spec.rb
271
291
  - spec/daigaku/loading/courses_spec.rb
272
292
  - spec/daigaku/loading/units_spec.rb
273
293
  - spec/daigaku/reference_solution_spec.rb
274
294
  - spec/daigaku/solution_spec.rb
295
+ - spec/daigaku/storeable_spec.rb
275
296
  - spec/daigaku/task_spec.rb
276
297
  - spec/daigaku/terminal/cli_spec.rb
277
298
  - spec/daigaku/terminal/courses_spec.rb
@@ -286,6 +307,7 @@ files:
286
307
  - spec/daigaku/unit_spec.rb
287
308
  - spec/daigaku/views/chapters_menu_spec.rb
288
309
  - spec/daigaku/views/courses_menu_spec.rb
310
+ - spec/daigaku/views/menu_spec.rb
289
311
  - spec/daigaku/views/task_view_spec.rb
290
312
  - spec/daigaku/views/units_menu_spec.rb
291
313
  - spec/daigaku/views_spec.rb
@@ -308,9 +330,9 @@ require_paths:
308
330
  - lib
309
331
  required_ruby_version: !ruby/object:Gem::Requirement
310
332
  requirements:
311
- - - ">="
333
+ - - "~>"
312
334
  - !ruby/object:Gem::Version
313
- version: '0'
335
+ version: '2.0'
314
336
  required_rubygems_version: !ruby/object:Gem::Requirement
315
337
  requirements:
316
338
  - - ">="
@@ -325,14 +347,16 @@ summary: Learning Ruby on the command line.
325
347
  test_files:
326
348
  - spec/daigaku/chapter_spec.rb
327
349
  - spec/daigaku/configuration_spec.rb
350
+ - spec/daigaku/congratulator_spec.rb
328
351
  - spec/daigaku/course_spec.rb
329
- - spec/daigaku/database_spec.rb
330
352
  - spec/daigaku/generator_spec.rb
353
+ - spec/daigaku/github_client_spec.rb
331
354
  - spec/daigaku/loading/chapters_spec.rb
332
355
  - spec/daigaku/loading/courses_spec.rb
333
356
  - spec/daigaku/loading/units_spec.rb
334
357
  - spec/daigaku/reference_solution_spec.rb
335
358
  - spec/daigaku/solution_spec.rb
359
+ - spec/daigaku/storeable_spec.rb
336
360
  - spec/daigaku/task_spec.rb
337
361
  - spec/daigaku/terminal/cli_spec.rb
338
362
  - spec/daigaku/terminal/courses_spec.rb
@@ -347,6 +371,7 @@ test_files:
347
371
  - spec/daigaku/unit_spec.rb
348
372
  - spec/daigaku/views/chapters_menu_spec.rb
349
373
  - spec/daigaku/views/courses_menu_spec.rb
374
+ - spec/daigaku/views/menu_spec.rb
350
375
  - spec/daigaku/views/task_view_spec.rb
351
376
  - spec/daigaku/views/units_menu_spec.rb
352
377
  - spec/daigaku/views_spec.rb
@@ -1,64 +0,0 @@
1
- require 'yaml/store'
2
- require 'fileutils'
3
-
4
- module Daigaku
5
-
6
- class Database
7
- include Singleton
8
-
9
- attr_reader :file
10
-
11
- def initialize
12
- @file = Daigaku.config.storage_file
13
- directory = File.dirname(@file)
14
- FileUtils.makedirs(directory) unless Dir.exist?(directory)
15
-
16
- @db = YAML::Store.new(@file)
17
- end
18
-
19
- def set(key, value)
20
- @db.transaction { @db[key.to_s] = value }
21
- end
22
-
23
- def get(key)
24
- @db.transaction { @db[key.to_s] }
25
- end
26
-
27
- def self.get(key)
28
- instance.get(key)
29
- end
30
-
31
- def self.set(key, value)
32
- instance.set(key, value)
33
- end
34
-
35
- def self.file
36
- instance.file
37
- end
38
-
39
- # Defines getter and setter methods for arbitrarily named methods.
40
- # @xample
41
- # Diagaku::Database.answer = 42
42
- # => saves 'answer: 42' to database
43
- #
44
- # Daigaku::Database.answer
45
- # => 42
46
- def self.method_missing(method, *args, &block)
47
- if method =~ /.*=$/
48
- if singleton_methods.include?(method.to_s.chop.to_sym)
49
- raise "There is a \"#{method.to_s.chop}\" instance method already " +
50
- "defined. This will lead to problems while getting values " +
51
- "from the database. Please use another key than " +
52
- "#{singleton_methods.map(&:to_s)}."
53
- end
54
-
55
- instance.set(method.to_s.gsub(/=$/, ''), args[0])
56
- elsif args.count == 0
57
- instance.get(method)
58
- else
59
- super
60
- end
61
- end
62
- end
63
-
64
- end
@@ -1,79 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Daigaku::Database do
4
-
5
- subject { Daigaku::Database.send(:new) }
6
-
7
- before do
8
- Daigaku::Configuration.send(:new)
9
-
10
- allow_any_instance_of(Daigaku::Configuration).to \
11
- receive(:storage_file) { local_storage_file }
12
- end
13
-
14
- it { is_expected.to respond_to :get }
15
- it { is_expected.to respond_to :set }
16
- it { is_expected.to respond_to :file }
17
-
18
- it "creates the database file(s) in the .daigaku directory on access" do
19
- Daigaku::Database.call_an_arbitrary_method
20
- expect(File.exist?(local_storage_file)).to be_truthy
21
- end
22
-
23
- it "allows setting arbitrary keys by setter methods" do
24
- expect { Daigaku::Database.brownie = "brownie" }
25
- .not_to raise_error
26
- end
27
-
28
- it "allows getting subsequently set keys" do
29
- Daigaku::Database.carrots = "carrots"
30
- expect(Daigaku::Database.carrots).to eq "carrots"
31
- end
32
-
33
- it "returns nil for not set keys" do
34
- expect(Daigaku::Database.hamburger).to be_nil
35
- end
36
-
37
- it "raises an method missing errror for non getter/setter methods" do
38
- expect { Daigaku::Database.arbitrary_method(1, 2) }
39
- .to raise_error NoMethodError
40
- end
41
-
42
- it "responds to ::get" do
43
- expect(Daigaku::Database).to respond_to :get
44
- end
45
-
46
- it "responds to ::set" do
47
- expect(Daigaku::Database).to respond_to :set
48
- end
49
-
50
- it "responds to ::file" do
51
- expect(Daigaku::Database).to respond_to :file
52
- end
53
-
54
- describe "::get" do
55
- it "returns the value of the given key" do
56
- toast = 'toast'
57
- Daigaku::Database.toast = toast
58
- expect(Daigaku::Database.get :toast).to eq toast
59
- end
60
- end
61
-
62
- describe "::set" do
63
- it "sets the value for the given key" do
64
- juice = 'orange juice'
65
- Daigaku::Database.set :juice, juice
66
- expect(Daigaku::Database.juice).to eq juice
67
- end
68
- end
69
-
70
- describe "::file" do
71
- it "returns the storage file path" do
72
- expect(Daigaku::Database.file).to eq Daigaku.config.storage_file
73
- end
74
- end
75
-
76
- it "raises an error if the related getter for a setter is already defined" do
77
- expect { Daigaku::Database.clone = 'defined' }.to raise_error
78
- end
79
- end