bloc 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ ### 0.0.10
2
+
3
+ * create, test, and patch commands added
4
+ * create the bloc directory on create if not already present
5
+ * add deployable key to manifest attr_accessors
6
+ * consolidate logic around running tests and patching
7
+ * applying patches is no longer a private method of the manifest
8
+
1
9
  ### 0.0.9
2
10
 
3
11
  * in_tmp_git mixin, and removed reliance on bundler/setup
data/bin/bloc CHANGED
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "rubygems"
4
-
5
4
  require "bloc"
6
5
 
7
6
  commands = {
8
7
  'validate' => proc { Bloc::Command::Validate.run },
9
- 'generate' => proc { Bloc::Command::Generate.run }
8
+ 'create' => proc { Bloc::Command::Create.run },
9
+ 'test' => proc { Bloc::Command::Test.run },
10
+ 'patch' => proc { Bloc::Command::Patch.run }
10
11
  }
11
- if ARGV.length == 1 && commands.keys.include?(ARGV.first.downcase)
12
+ if commands.keys.include?(ARGV.first.downcase)
12
13
  begin
13
14
  commands[ARGV.first.downcase].call
14
15
  rescue => e
@@ -20,8 +21,10 @@ else
20
21
  bloc <command> [options]
21
22
 
22
23
  Commands:
23
- validate
24
- generate ["Course name"]
24
+ validate Attempt to parse the manifest and check for the existence of default files
25
+ create["Course name"] Create a course manifest with the specified name prefilled
26
+ test [chapter-number] If chapter number is specified, run tests for that chapter. If not, run all tests in order.
27
+ patch [chapter-number] Same as "test", except apply patches first (if present)
25
28
  eos
26
29
  puts helpstring
27
30
  end
@@ -1,5 +1,7 @@
1
1
  require "bloc/command/validate.rb"
2
- require "bloc/command/generate.rb"
2
+ require "bloc/command/create.rb"
3
+ require "bloc/command/test.rb"
4
+ require "bloc/command/patch.rb"
3
5
  require "bloc/models.rb"
4
6
  require "bloc/manifest.rb"
5
7
 
@@ -0,0 +1,21 @@
1
+ module Bloc
2
+ module Command
3
+ class Create
4
+ def self.run(*args)
5
+ name = ARGV[1]
6
+ if name.nil?
7
+ raise "Please specify a name.".red
8
+ end
9
+ course = Bloc::Models::Course.new(:name => name, :description => "")
10
+ chapters = []
11
+ manifest = Bloc::Manifest.new({"course" => course, "chapters" => chapters})
12
+ begin
13
+ manifest.write
14
+ puts "Wrote manifest.".green
15
+ rescue Exception => e
16
+ raise e.to_s.red
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module Bloc
2
+ module Command
3
+ class Patch
4
+ def self.run(*args)
5
+ manifest = Manifest.parse
6
+ if ARGV[1].nil?
7
+ manifest.run_tests(:apply_patch => true)
8
+ else
9
+ manifest.run_tests(:chapter => ARGV[1].to_i, :apply_patch => true)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Bloc
2
+ module Command
3
+ class Test
4
+ def self.run(*args)
5
+ manifest = Manifest.parse
6
+ if ARGV[1].nil?
7
+ manifest.run_tests
8
+ else
9
+ manifest.run_tests(:chapter => ARGV[1].to_i)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -8,10 +8,11 @@ module Bloc
8
8
  MANIFEST_PATH = File.join("bloc", "bloc_manifest.json")
9
9
  INVALID_MANIFEST = "Invalid JSON in Bloc Manifest: #{MANIFEST_PATH}".red
10
10
  VALID_MANIFEST = "Valid Bloc Manifest".green
11
+ NO_SUCH_CHAPTER = "No such chapter.".red
11
12
 
12
13
  include TempGit
13
14
 
14
- attr_accessor :course, :chapters
15
+ attr_accessor :course, :chapters, :deployable
15
16
 
16
17
  def initialize(options)
17
18
  @course = options["course"]
@@ -19,6 +20,7 @@ module Bloc
19
20
  end
20
21
 
21
22
  def write
23
+ Dir.mkdir(File.dirname(MANIFEST_PATH))
22
24
  File.open(MANIFEST_PATH, "w") do |file|
23
25
  file.write(JSON.pretty_generate(to_h))
24
26
  end
@@ -52,10 +54,21 @@ module Bloc
52
54
  Manifest.new({"course" => course, "chapters" => chapters})
53
55
  end
54
56
 
55
- def run_tests
57
+ def run_tests(options = {})
58
+ defaults = {:chapter => nil, :apply_patch => false}
59
+ options = defaults.merge(options)
60
+
56
61
  in_tmp_git do
57
- @chapters.each do |chapter|
58
- chapter.run_tests
62
+ if options[:chapter].nil?
63
+ @chapters.each do |chapter|
64
+ chapter.apply_patch if options[:apply_patch]
65
+ chapter.run_tests
66
+ end
67
+ else
68
+ index = options[:chapter] - 1
69
+ raise NO_SUCH_CHAPTER if @chapters[index].nil?
70
+ @chapters[index].apply_patch if options[:apply_patch]
71
+ @chapters[index].run_tests
59
72
  end
60
73
  end
61
74
  end
@@ -20,7 +20,6 @@ module Bloc
20
20
  TEST_PASSED = "Passed: %s".green
21
21
 
22
22
  def run_tests
23
- apply_patch
24
23
  unless @patch.nil?
25
24
  results = test
26
25
  results["tests"].each do |test_result|
@@ -37,6 +36,12 @@ module Bloc
37
36
  File.exists?("bloc/#{@patch}")
38
37
  end
39
38
 
39
+ def apply_patch
40
+ unless @patch.nil?
41
+ `patch < bloc/#{@patch}`
42
+ end
43
+ end
44
+
40
45
  private
41
46
 
42
47
  def test
@@ -45,12 +50,6 @@ module Bloc
45
50
  File.delete("results.json")
46
51
  results
47
52
  end
48
-
49
- def apply_patch
50
- unless @patch.nil?
51
- `patch < bloc/#{@patch}`
52
- end
53
- end
54
53
  end
55
54
  end
56
55
  end
@@ -1,3 +1,3 @@
1
1
  module Bloc
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bloc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-03-06 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &70126183569760 !ruby/object:Gem::Requirement
17
+ requirement: &70339116316320 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70126183569760
25
+ version_requirements: *70339116316320
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: fakefs
28
- requirement: &70126183569340 !ruby/object:Gem::Requirement
28
+ requirement: &70339116315900 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70126183569340
36
+ version_requirements: *70339116315900
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: ruby-debug19
39
- requirement: &70126183568920 !ruby/object:Gem::Requirement
39
+ requirement: &70339116315480 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70126183568920
47
+ version_requirements: *70339116315480
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: json
50
- requirement: &70126183568500 !ruby/object:Gem::Requirement
50
+ requirement: &70339116315060 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70126183568500
58
+ version_requirements: *70339116315060
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: colorize
61
- requirement: &70126183568080 !ruby/object:Gem::Requirement
61
+ requirement: &70339116314640 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *70126183568080
69
+ version_requirements: *70339116314640
70
70
  description: A command-line tool for Bloc
71
71
  email:
72
72
  - roshan.choxi@gmail.com
@@ -86,7 +86,9 @@ files:
86
86
  - bloc.gemspec
87
87
  - lib/bloc.rb
88
88
  - lib/bloc/command.rb
89
- - lib/bloc/command/generate.rb
89
+ - lib/bloc/command/create.rb
90
+ - lib/bloc/command/patch.rb
91
+ - lib/bloc/command/test.rb
90
92
  - lib/bloc/command/validate.rb
91
93
  - lib/bloc/hash_constructed.rb
92
94
  - lib/bloc/manifest.rb
@@ -1,12 +0,0 @@
1
- module Bloc
2
- module Command
3
- class Generate
4
- def self.run(*args)
5
- course = Bloc::Models::Course.new(:name => "My course", :description => "")
6
- chapters = []
7
- manifest = Bloc::Manifest.new({"course" => course, "chapters" => chapters})
8
- manifest.write
9
- end
10
- end
11
- end
12
- end