rebundler 0.2.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: b98128fc72f25553bf3989f1cda39f09d0b38553185bbb9bd6e92a3fe4646cc8
4
- data.tar.gz: 580694dd7a91592f95f1c32173e625f1a17c6c7dfc9bfc1c708bc565e422f4fa
3
+ metadata.gz: 3a699f86063d76f1777e967eb5aa993fe2d65c355812dbd50ec4a599653bac37
4
+ data.tar.gz: b1724cdc2493ef5745b23acac611c4a820fce04afaff0b0e7983085a291639e1
5
5
  SHA512:
6
- metadata.gz: c83d1b995968f668a96b656036c9ba19f646bf3af2ee32611867ba820894acdfbead0b9662e60f1db3d08e1a8cef8476283cf3be855aefed921b7bf00e15d5d9
7
- data.tar.gz: a4f681d93564b7111de675f8b576f62b3837fe0f2704f75cfa96d4a0ff7a0b106e726c09a26e7a8b8744a44f2ba24200a95be42249a8987f991583c1bf98c257
6
+ metadata.gz: a8be976be4c69cba77b1d4a031adfefb52917637693f6ebd2f64307df602d397904f1c1f38321ac0b7c1c8225374550da3e79b8242b37ac9311b09334da3daf6
7
+ data.tar.gz: f7eb7094cabef8b94a49a82e5ad7d295da07e8d66a91d6b77bd669c6f04176003acf3594acb058b80258a5632aece21492c88283cb186668b10aa1131c49a316
data/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2025-12-19
4
+
5
+ - Fixed bug where comment on last gem in a block was not overwritten.
6
+
7
+ ## [0.3.0] - 2025-12-18
8
+
9
+ - Add support for tabs instead of spaces.
10
+ - Add support for `git_source`.
11
+ - Some refactoring.
12
+
13
+ ## [0.2.0] - 2025-12-06
14
+
15
+ Notable changes:
16
+
17
+ - Add CI mode.
18
+
19
+ If you run `bundle exec rebundle --ci`, rebundler will run in CI mode, which will compare the output
20
+ of the current Gemfile to a freshly formatted one. If there are differences, rebundler will exit
21
+ with a non-zero status code. This does not write to the Gemfile.
22
+
23
+ - Major internal refactor.
24
+
25
+ ## [0.1.3] - 2025-09-09
26
+
27
+ Notable changes:
28
+
29
+ - Merge equal groups into each other.
30
+
31
+ ## [0.1.2] - 2025-09-09
32
+
33
+ Notable changes:
34
+
35
+ - Ignore dashes and underscores when sorting gems.
36
+
37
+ ## [0.1.1] - 2025-09-09
38
+
39
+ No notable changes.
40
+
3
41
  ## [0.1.0] - 2024-11-17
4
42
 
5
- - Initial release
43
+ Initial release.
data/README.md CHANGED
@@ -59,6 +59,15 @@ This does **not** load the plugin and means you have to run rebundler yourself b
59
59
  $ bundle exec rebundle
60
60
  ```
61
61
 
62
+ ### 3. CI mode
63
+
64
+ If you run `bundle exec rebundle --ci`, rebundler will run in CI mode, which will compare the output
65
+ of the current Gemfile to a freshly formatted one.
66
+
67
+ If there are differences, rebundler will exit with a non-zero status code.
68
+
69
+ This does not write to the Gemfile.
70
+
62
71
  ## Development
63
72
 
64
73
  After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -3,39 +3,29 @@
3
3
  module Rebundler
4
4
  class Serializer
5
5
  def self.node_to_s(node)
6
- return if node.nil?
6
+ lines = node.location.slice.lines
7
7
 
8
- case node.type
9
- when :call_node
10
- [node.name, node_to_s(node.arguments)].compact.join(" ")
11
- when :keyword_hash_node
12
- node.elements.map do |element|
13
- key = node_to_s(element.key)
14
- value = node_to_s(element.value)
8
+ # If a block is given, we replace the content of the node's block
9
+ # with the content of the passed block.
10
+ if node.block && block_given? && lines.size > 1
11
+ depth = find_depth(node)
12
+ tab_or_space = find_spacing_character(node)
15
13
 
16
- "#{key} #{value}"
17
- end
18
- when :symbol_node
19
- "#{node.opening}#{node.value}#{node.closing}"
20
- when :string_node
21
- "#{node.opening}#{node.content}#{node.closing}"
22
- when :array_node
23
- separator = node.opening == "[" ? ", " : " "
14
+ indented_content = yield.lines.map { |line| (tab_or_space * depth) + line }.join
24
15
 
25
- node.opening + node.elements.map do |element|
26
- node_to_s(element)
27
- end.join(separator) + node.closing
28
- when :true_node
29
- "true"
30
- when :false_node
31
- "false"
32
- when :arguments_node
33
- return if node.child_nodes.empty?
34
-
35
- node.child_nodes.map { |child| node_to_s(child) }.join(", ")
16
+ lines.first + indented_content + "\n" + lines.last
36
17
  else
37
- raise Rebundler::Error, "Unsupported node type: #{node.type}"
18
+ node.location.slice
38
19
  end
39
20
  end
21
+
22
+ def self.find_depth(node)
23
+ node.block.body.location.start_column
24
+ end
25
+
26
+ def self.find_spacing_character(node)
27
+ # Assume it's formatted with tabs if there is ANY tab in the whole block of code.
28
+ node.location.slice.include?("\t") ? "\t" : " "
29
+ end
40
30
  end
41
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rebundler
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -16,9 +16,12 @@ module Rebundler
16
16
  when :gem
17
17
  parsed_gem = GemFetcher.parse_gem(node)
18
18
  @current_set.gems << parsed_gem if parsed_gem
19
+ when :git_source
20
+ @parser.preamble_nodes << node
19
21
  when *BLOCK_NODES
20
22
  if node.block
21
- name = Serializer.node_to_s(node)
23
+ # Use the full block declaration (e.g., "group :development do") as the unique name
24
+ name = node.location.slice.lines.first.strip
22
25
 
23
26
  previous_set = @current_set
24
27
  @current_set = @parser.find_or_build_set(name:, node:)
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "forwardable"
4
+
3
5
  module Rebundler
4
6
  class Writer
7
+ extend Forwardable
8
+
9
+ def_delegators :@parser, :preamble_nodes, :gem_sets, :frozen_string_literal
10
+
5
11
  def initialize(parser)
6
12
  @parser = parser
7
13
  end
@@ -16,43 +22,24 @@ module Rebundler
16
22
  end
17
23
 
18
24
  gem_sets.sort.each do |set|
19
- set_buffer = []
20
-
21
- set_buffer << [Serializer.node_to_s(set.node), set.node.block.opening].compact.join(" ") if set.node
22
-
23
- set_buffer << [set.plugins, set.gems].map do |nodes|
25
+ gem_content = [set.plugins, set.gems].map do |nodes|
24
26
  sorted = nodes.sort_by { |node| node[:name].tr("-_", "").downcase }
25
27
 
26
28
  sorted.map do |gem|
27
- line = +""
28
- line << " " if set.node
29
- line << Serializer.node_to_s(gem[:node])
29
+ line = +Serializer.node_to_s(gem[:node])
30
30
  line << " # #{gem[:summary]}" if gem[:summary]
31
-
32
31
  line
33
32
  end.join("\n")
34
33
  end.reject(&:empty?).join("\n\n")
35
34
 
36
- set_buffer << set.node.block.closing if set.node&.block
37
-
38
- buffer << set_buffer.join("\n")
35
+ buffer << if set.node
36
+ Serializer.node_to_s(set.node) { gem_content }
37
+ else
38
+ gem_content
39
+ end
39
40
  end
40
41
 
41
42
  buffer.reject(&:empty?).join("\n\n") + "\n"
42
43
  end
43
-
44
- private
45
-
46
- def preamble_nodes
47
- @parser.preamble_nodes
48
- end
49
-
50
- def gem_sets
51
- @parser.gem_sets
52
- end
53
-
54
- def frozen_string_literal
55
- @parser.frozen_string_literal
56
- end
57
44
  end
58
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rebundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Paagman