rebundler 0.2.0 → 0.3.0

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: fa77336a2666fe374595f649959ec9a0ad40f390e21c55d8591a65c5e2561d5e
4
+ data.tar.gz: d6972a708a8e5c2e79b36c2d8fc384d6f287d691c4cac286e7aa5150fb3a380d
5
5
  SHA512:
6
- metadata.gz: c83d1b995968f668a96b656036c9ba19f646bf3af2ee32611867ba820894acdfbead0b9662e60f1db3d08e1a8cef8476283cf3be855aefed921b7bf00e15d5d9
7
- data.tar.gz: a4f681d93564b7111de675f8b576f62b3837fe0f2704f75cfa96d4a0ff7a0b106e726c09a26e7a8b8744a44f2ba24200a95be42249a8987f991583c1bf98c257
6
+ metadata.gz: de9facad64186665e93e445f39d97296046bad9a66c8d3c0a12cf5b9e2fc824609628d85c8ae414a947e81e8e3c1c282f6ab70c93648185eb34bf7c4085fcb5f
7
+ data.tar.gz: ac8700216a87393b021a8d3fa6da313473e810945da8d990c1b562cae6ce6e038edc9e674d9a69782c73fafac23201072935359dd837c231f52588c50c35f913
data/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2025-12-18
4
+
5
+ - Add support for tabs instead of spaces.
6
+ - Add support for `git_source`.
7
+ - Some refactoring.
8
+
9
+ ## [0.2.0] - 2025-12-06
10
+
11
+ Notable changes:
12
+
13
+ - Add CI mode.
14
+
15
+ If you run `bundle exec rebundle --ci`, rebundler will run in CI mode, which will compare the output
16
+ of the current Gemfile to a freshly formatted one. If there are differences, rebundler will exit
17
+ with a non-zero status code. This does not write to the Gemfile.
18
+
19
+ - Major internal refactor.
20
+
21
+ ## [0.1.3] - 2025-09-09
22
+
23
+ Notable changes:
24
+
25
+ - Merge equal groups into each other.
26
+
27
+ ## [0.1.2] - 2025-09-09
28
+
29
+ Notable changes:
30
+
31
+ - Ignore dashes and underscores when sorting gems.
32
+
33
+ ## [0.1.1] - 2025-09-09
34
+
35
+ No notable changes.
36
+
3
37
  ## [0.1.0] - 2024-11-17
4
38
 
5
- - Initial release
39
+ 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.
@@ -5,37 +5,22 @@ module Rebundler
5
5
  def self.node_to_s(node)
6
6
  return if node.nil?
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 node.block && block_given?
9
+ indent = detect_indent(node)
10
+ indented_content = yield.lines.map { |line| indent + line.lstrip }.join
15
11
 
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 == "[" ? ", " : " "
24
-
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(", ")
12
+ stripped_block = node.location.slice.gsub(node.block.body.location.slice, "BLOCK")
13
+ stripped_block.gsub(/[#{WHITESPACE_CHARACTERS}]*BLOCK/, indented_content)
36
14
  else
37
- raise Rebundler::Error, "Unsupported node type: #{node.type}"
15
+ node.location.slice
38
16
  end
39
17
  end
18
+
19
+ def self.detect_indent(node)
20
+ return "" unless node
21
+
22
+ second_line = node.location.slice.lines[1]
23
+ second_line&.[](/\A[#{WHITESPACE_CHARACTERS}]*/) || " "
24
+ end
40
25
  end
41
26
  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.0"
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:)
@@ -16,26 +16,21 @@ module Rebundler
16
16
  end
17
17
 
18
18
  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|
19
+ gem_content = [set.plugins, set.gems].map do |nodes|
24
20
  sorted = nodes.sort_by { |node| node[:name].tr("-_", "").downcase }
25
21
 
26
22
  sorted.map do |gem|
27
- line = +""
28
- line << " " if set.node
29
- line << Serializer.node_to_s(gem[:node])
23
+ line = +Serializer.node_to_s(gem[:node])
30
24
  line << " # #{gem[:summary]}" if gem[:summary]
31
-
32
25
  line
33
26
  end.join("\n")
34
27
  end.reject(&:empty?).join("\n\n")
35
28
 
36
- set_buffer << set.node.block.closing if set.node&.block
37
-
38
- buffer << set_buffer.join("\n")
29
+ buffer << if set.node
30
+ Serializer.node_to_s(set.node) { gem_content }
31
+ else
32
+ gem_content
33
+ end
39
34
  end
40
35
 
41
36
  buffer.reject(&:empty?).join("\n\n") + "\n"
data/lib/rebundler.rb CHANGED
@@ -8,6 +8,8 @@ loader.setup
8
8
  module Rebundler
9
9
  class Error < StandardError; end
10
10
 
11
+ WHITESPACE_CHARACTERS = [" ", "\t"].join.freeze
12
+
11
13
  SORTABLE_NODES = %i[plugin gem].freeze
12
14
  BLOCK_NODES = %i[gemspec git group path platforms ruby source].freeze
13
15
  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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Paagman