annotate_gem 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 047f6b2c6f2fb2d56e8fde53ba869c87000697b6
4
- data.tar.gz: f98ae9c02b0f80371fca64018519ceb587ed1e39
3
+ metadata.gz: e19ea744fca0e12094d208b16959a8d80e343769
4
+ data.tar.gz: 38bbd3f8c59b331f7346caac39d8420aa1680049
5
5
  SHA512:
6
- metadata.gz: bc0f28fcfa956836ff846c9fcde3fa39fb3d98834a8910aabdc1c3c140895cc1b0acb105b8fc9ed25cd49c414dabd4dd56501135c966ba732267f1a16511a661
7
- data.tar.gz: dda56b77cfe1b700581bb1be90e94e733fd1845c3d4c5c38be965decdda5d3932a4ef1eaee2c7e9b3961a5733a4e72289f7a36abe60f683599a693447f325db6
6
+ metadata.gz: d71370492e61059f406c03f527aa6512c09fa901ff273ca5a853f34cca6c7e6ba8345b4a2c237ae820e32996a194de42a2cf1e503050d3cdc130a1e484d101b1
7
+ data.tar.gz: 1122146e16934a15a511cd0e072745bd68c52385d51083c33396697ad0cf1423204df64d0188ae1a5ebec5407b8590a73cd4c30ca2e8a502f24da5291f879fa7
@@ -17,6 +17,10 @@ module AnnotateGem
17
17
  comment = "#{leading_spaces}# #{info}"
18
18
  end
19
19
 
20
+ def inline_comment
21
+ "#{original_line.chomp} # #{info}"
22
+ end
23
+
20
24
  def info
21
25
  output = if options[:website_only]
22
26
  website
@@ -35,12 +39,16 @@ module AnnotateGem
35
39
  private
36
40
 
37
41
  def already_added_comment
38
- prev_line_comment && prev_line_comment.include?(comment)
42
+ !options[:inline] && prev_line_comment && prev_line_comment.include?(comment)
39
43
  end
40
44
 
41
45
  # if there exists a prev_line_comment and the user has specified new_comments_only
42
46
  def existing_comment_option
43
- prev_line_comment && options[:new_comments_only]
47
+ (options[:new_comments_only] && prev_line_comment) || (options[:inline] && original_line_has_comment?)
48
+ end
49
+
50
+ def original_line_has_comment?
51
+ original_line.include?("#")
44
52
  end
45
53
 
46
54
  def leading_spaces_count
@@ -31,7 +31,12 @@ module AnnotateGem
31
31
 
32
32
  def write_comments
33
33
  gem_lines.reverse.each do |gem_line|
34
- source.insert(gem_line.location, gem_line.comment) if gem_line.should_insert?
34
+ next unless gem_line.should_insert?
35
+ if options[:inline]
36
+ source[gem_line.location] = gem_line.inline_comment
37
+ else
38
+ source.insert(gem_line.location, gem_line.comment)
39
+ end
35
40
  end
36
41
  File.write(gemfile_path, source.join)
37
42
  end
@@ -38,9 +38,13 @@ module AnnotateGem
38
38
  end
39
39
 
40
40
  def add_gemfile_comment_options(opts)
41
- opts.on("--new-comments-only", "Only add a comment to gemfile if there isn't a comment already") do
41
+ opts.on("--new-comments-only", "Only add a comment to gemfile if there isn't a comment already (for non-inline comments)") do
42
42
  options[:new_comments_only] = true
43
43
  end
44
+
45
+ opts.on("--inline", "Inline the comment") do
46
+ options[:inline] = true
47
+ end
44
48
  end
45
49
 
46
50
  def add_banner(opts)
@@ -1,4 +1,4 @@
1
1
  module AnnotateGem
2
- VERSION = "0.0.10".freeze
2
+ VERSION = "0.0.11".freeze
3
3
  DESCRIPTION = "Add comments to your Gemfile with each dependency's description.".freeze
4
4
  end
@@ -51,6 +51,16 @@ class AnnotateGem::GemLineTest < Minitest::Test
51
51
  refute gem_line.should_insert?
52
52
  end
53
53
 
54
+ def test_should_insert__with_inline_and_existing_comment
55
+ gem_line = create_gem_line(
56
+ original_line: "gem 'annotate_gem' # This is an existing comment\n",
57
+ options: { inline: true }
58
+ )
59
+ spec = stub(summary: "Hello world", homepage: "http://example.com")
60
+ gem_line.spec = spec
61
+ refute gem_line.should_insert?
62
+ end
63
+
54
64
  def test_comment
55
65
  gem_line = create_gem_line
56
66
  spec = stub(summary: "Hello world", homepage: "http://example.com")
@@ -46,6 +46,16 @@ class AnnotateGem::GemfileTest < Minitest::Test
46
46
  end
47
47
  end
48
48
 
49
+ def test_write_comments_with_inline
50
+ with_gemfile("gem 'rails'") do |path|
51
+ gemfile = AnnotateGem::Gemfile.new(path, inline: true)
52
+ gemfile.gem_lines = [mock(location: 0, inline_comment: "gem 'rails' # Rails description!\n", should_insert?: true)]
53
+ gemfile.source = ["gem 'rails'"]
54
+ gemfile.write_comments
55
+ assert_equal "gem 'rails' # Rails description!\n", File.read(path)
56
+ end
57
+ end
58
+
49
59
  def test_that_options_are_passed_through
50
60
  AnnotateGem::GemLine.expects(:new).with(
51
61
  name: "rails",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotate_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Tse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler