psych-merge 7.0.0 → 7.1.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/LICENSE.md +13 -0
- data/README.md +498 -0
- data/lib/psych/merge/comment_tracker.rb +73 -0
- data/lib/psych/merge/conflict_resolver.rb +2337 -0
- data/lib/psych/merge/debug_logger.rb +45 -0
- data/lib/psych/merge/diff_mapper.rb +249 -0
- data/lib/psych/merge/emitter.rb +250 -0
- data/lib/psych/merge/file_analysis.rb +564 -0
- data/lib/psych/merge/freeze_node.rb +97 -0
- data/lib/psych/merge/mapping_match_refiner.rb +258 -0
- data/lib/psych/merge/merge_result.rb +156 -0
- data/lib/psych/merge/node_type_normalizer.rb +73 -0
- data/lib/psych/merge/node_wrapper.rb +362 -0
- data/lib/psych/merge/partial_template_merger.rb +98 -0
- data/lib/psych/merge/smart_merger.rb +328 -0
- data/lib/psych/merge/version.rb +5 -3
- data/lib/psych/merge.rb +293 -63
- data/lib/psych-merge.rb +10 -1
- data/sig/psych/merge.rbs +8 -0
- data.tar.gz.sig +0 -0
- metadata +289 -12
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5489a19762de99f5b8b99c8b3ad8252a3c6d5fbc4acb2973c8c7bc0a19628d64
|
|
4
|
+
data.tar.gz: 9445a554b835f145246c5360232072dcbab1202a1d900a805b7a65bd5028426e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eccc4b1be4ca2ddaabd2b7ce4925fc776eb55b2b768608618e3aa580674c0c0d6a09f99463dc94934d79f0600aa5a430a7a299539c6336b4a534ae02a7267b8e
|
|
7
|
+
data.tar.gz: 45f58cdb0b7448e8975ba2d006a4227225d7d594e9e18a19b036974582048f8fe2405f3733d5efb45b3f881aad422ba6fdf068332323be7421b261334b93086e
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
This project is made available under the following licenses.
|
|
4
|
+
Choose the option that best fits your use case:
|
|
5
|
+
|
|
6
|
+
- [AGPL-3.0-only](https://github.com/structuredmerge/structuredmerge-ruby/blob/main/AGPL-3.0-only.md)
|
|
7
|
+
- [PolyForm-Small-Business-1.0.0](https://github.com/structuredmerge/structuredmerge-ruby/blob/main/PolyForm-Small-Business-1.0.0.md)
|
|
8
|
+
|
|
9
|
+
If none of the above licenses fit your use case, please [contact us](mailto:floss@galtzo.com) to discuss a custom commercial license.
|
|
10
|
+
|
|
11
|
+
## Copyright Notice
|
|
12
|
+
|
|
13
|
+
- Required Notice: Copyright (c) 2026 Peter H. Boling
|
data/README.md
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
<a href="https://github.com/structuredmerge"><img alt="structuredmerge Logo by GitHub" src="https://github.com/structuredmerge.png?size=192" width="14%" align="right"/></a>
|
|
2
|
+
|
|
3
|
+
# ☯️ Psych::Merge
|
|
4
|
+
|
|
5
|
+
[![Version][👽versioni]][👽version] [![Ruby Users Forum][✉️ruby-forum-top-img]][✉️ruby-forum] [![GitHub tag (latest SemVer)][⛳️tag-img]][⛳️tag] [![License: AGPL-3.0-only OR PolyForm-Small-Business-1.0.0][📄license-img]][📄license] [![Total downloads][👽dl-ranki]][👽dl-rank] [![CI Current][🚎11-c-wfi]][🚎11-c-wf]
|
|
6
|
+
|
|
7
|
+
`if ci_badges.map(&:color).detect { it != "green"}` ☝️ [let me know on Discord][✉️discord-invite] or [RubyForum][✉️ruby-forum], as I may have missed the notification.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`if ci_badges.map(&:color).all? { it == "green"}` 👇️ send money so I can do more of this. FLOSS maintenance is now my full-time job.
|
|
12
|
+
|
|
13
|
+
[![Sponsor Me on Github][🖇sponsor-img]][🖇sponsor] [![Liberapay Goal Progress][⛳liberapay-img]][⛳liberapay] [![Donate on PayPal][🖇paypal-img]][🖇paypal] [![Buy me a coffee][🖇buyme-small-img]][🖇buyme] [![Donate at ko-fi.com][🖇kofi-img]][🖇kofi]
|
|
14
|
+
|
|
15
|
+
<details markdown="1">
|
|
16
|
+
<summary>👣 How will this project approach the September 2025 hostile takeover of RubyGems? 🚑️</summary>
|
|
17
|
+
|
|
18
|
+
I've summarized my thoughts in [this blog post](https://dev.to/galtzo/hostile-takeover-of-rubygems-my-thoughts-5hlo).
|
|
19
|
+
|
|
20
|
+
</details>
|
|
21
|
+
|
|
22
|
+
## 🌻 Synopsis <a href="https://discord.gg/3qme4XHNKN"><img alt="Galtzo FLOSS Logo by Aboling0, CC BY-SA 4.0" src="https://logos.galtzo.com/assets/images/galtzo-floss/avatar-128px.svg" width="8%" align="right"/></a> <a href="https://ruby-toolbox.com"><img alt="ruby-lang Logo, Yukihiro Matsumoto, Ruby Visual Identity Team, CC BY-SA 2.5" src="https://logos.galtzo.com/assets/images/ruby-lang/avatar-128px.svg" width="8%" align="right"/></a>
|
|
23
|
+
|
|
24
|
+
Psych::Merge intelligently merges two versions of a YAML file using Psych-backed
|
|
25
|
+
AST analysis. It is built on [ast-merge][ast-merge] and [tree_haver][tree_haver],
|
|
26
|
+
and shares YAML-family behavior with [yaml-merge][yaml-merge].
|
|
27
|
+
|
|
28
|
+
`psych-merge` is a YAML provider gem, not an alternate home for YAML merge
|
|
29
|
+
semantics. Psych-specific code should be isolated behind its TreeHaver backend
|
|
30
|
+
adapter. Merge behavior should consume normalized YAML-family owners and
|
|
31
|
+
source-preserving edit plans supplied by the StructuredMerge stack. Partial YAML
|
|
32
|
+
insertion, replacement, and removal should route through `ast-crispr` rather
|
|
33
|
+
than converting documents to Ruby objects and serializing them with `Psych.dump`.
|
|
34
|
+
|
|
35
|
+
### Key Features
|
|
36
|
+
|
|
37
|
+
- **Psych-Powered**: Uses Ruby's built-in Psych parser for YAML AST analysis
|
|
38
|
+
- **YAML-Aware**: Understands YAML structure including mappings, sequences, and scalars
|
|
39
|
+
- **YAML Family Behavior**: Delegates shared YAML merge semantics to `yaml-merge`
|
|
40
|
+
- **Intelligent**: Matches nodes by structural signatures
|
|
41
|
+
- **Fuzzy Key Matching**: `MappingMatchRefiner` matches similar keys (e.g., `database_url` ↔ `db_url`)
|
|
42
|
+
using Levenshtein distance for typos and naming convention differences
|
|
43
|
+
- **Comment-Preserving**: Comments are preserved in their context
|
|
44
|
+
- **Freeze Block Support**: Respects freeze markers (default: `psych-merge:freeze` / `psych-merge:unfreeze`) for merge control - customizable to match your project's conventions
|
|
45
|
+
- **Full Provenance**: Tracks origin of every node
|
|
46
|
+
- **StructuredMerge Native**: Depends on `ast-merge`, `tree_haver`, `yaml-merge`, and Ruby's built-in `psych`
|
|
47
|
+
- **Customizable**:
|
|
48
|
+
- `signature_generator` - callable custom signature generators
|
|
49
|
+
- `preference` - setting of `:template`, `:destination`, or a Hash for per-node-type preferences
|
|
50
|
+
- `node_splitter` - Hash mapping node types to callables for per-node-type merge customization (see [ast-merge][ast-merge] docs)
|
|
51
|
+
- `add_template_only_nodes` - setting to retain nodes that do not exist in destination
|
|
52
|
+
- `freeze_token` - customize freeze block markers (default: `"psych-merge"`)
|
|
53
|
+
- `match_refiners` - array of refiners for fuzzy matching (e.g., `MappingMatchRefiner`)
|
|
54
|
+
|
|
55
|
+
### Supported Node Types
|
|
56
|
+
|
|
57
|
+
| Node Type | Signature Format | Matching Behavior |
|
|
58
|
+
|-----------|------------------|-------------------|
|
|
59
|
+
| Mapping | `[:mapping, key_signatures...]` | Mappings match by their key structure |
|
|
60
|
+
| Sequence | `[:sequence, element_count]` | Sequences match by position and type |
|
|
61
|
+
| Scalar | `[:scalar, value]` | Scalars match by value |
|
|
62
|
+
| Alias | `[:alias, anchor]` | Aliases match by anchor name |
|
|
63
|
+
|
|
64
|
+
### Example
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
require "psych/merge"
|
|
68
|
+
|
|
69
|
+
template = File.read("template.yml")
|
|
70
|
+
destination = File.read("destination.yml")
|
|
71
|
+
|
|
72
|
+
merger = Psych::Merge::SmartMerger.new(template, destination)
|
|
73
|
+
result = merger.merge
|
|
74
|
+
|
|
75
|
+
File.write("merged.yml", result.to_yaml)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
[ast-merge]: https://github.com/structuredmerge/structuredmerge-ruby/tree/main/gems/ast-merge
|
|
79
|
+
[tree_haver]: https://github.com/structuredmerge/structuredmerge-ruby/tree/main/gems/tree_haver
|
|
80
|
+
[yaml-merge]: https://github.com/structuredmerge/structuredmerge-ruby/tree/main/gems/yaml-merge
|
|
81
|
+
|
|
82
|
+
## 💡 Info you can shake a stick at
|
|
83
|
+
|
|
84
|
+
| Tokens to Remember | [![Gem name][⛳️name-img]][⛳️gem-name] [![Gem namespace][⛳️namespace-img]][⛳️gem-namespace] |
|
|
85
|
+
|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
86
|
+
| Works with MRI Ruby 4 | [![Ruby current Compat][💎ruby-c-i]][🚎11-c-wf]|
|
|
87
|
+
| Support & Community | [![Join Me on Daily.dev's RubyFriends][✉️ruby-friends-img]][✉️ruby-friends] [![Get help from RubyForum][✉️ruby-forum-img]][✉️ruby-forum] [![Live Chat on Discord][✉️discord-invite-img-ftb]][✉️discord-invite] [![Get help from me on Upwork][👨🏼🏫expsup-upwork-img]][👨🏼🏫expsup-upwork] [![Get help from me on Codementor][👨🏼🏫expsup-codementor-img]][👨🏼🏫expsup-codementor] |
|
|
88
|
+
| Source | [![Source on GitLab.com][📜src-gl-img]][📜src-gl] [![Source on CodeBerg.org][📜src-cb-img]][📜src-cb] [![Source on GitHub.com][📜src-gh-img]][📜src-gh] [![The best SHA: dQw4w9WgXcQ!][🧮kloc-img]][🧮kloc] |
|
|
89
|
+
| Documentation | [![Current release on RubyDoc.info][📜docs-cr-rd-img]][🚎yard-current] [![YARD on Galtzo.com][📜docs-head-rd-img]][🚎yard-head] [![Maintainer Blog][🚂maint-blog-img]][🚂maint-blog] [![GitLab Wiki][📜gl-wiki-img]][📜gl-wiki] [![GitHub Wiki][📜gh-wiki-img]][📜gh-wiki] |
|
|
90
|
+
| Compliance | [![License: AGPL-3.0-only OR PolyForm-Small-Business-1.0.0][📄license-img]][📄license] [![Apache license compatibility: Category X][📄license-compat-img]][📄license-compat] [![📄ilo-declaration-img]][📄ilo-declaration] [![Security Policy][🔐security-img]][🔐security] [![Contributor Covenant 2.1][🪇conduct-img]][🪇conduct] [![SemVer 2.0.0][📌semver-img]][📌semver] |
|
|
91
|
+
| Style | [![Enforced Code Style Linter][💎rlts-img]][💎rlts] [![Keep-A-Changelog 1.0.0][📗keep-changelog-img]][📗keep-changelog] [![Gitmoji Commits][📌gitmoji-img]][📌gitmoji] [![Compatibility appraised by: appraisal2][💎appraisal2-img]][💎appraisal2] |
|
|
92
|
+
| Maintainer 🎖️ | [![Follow Me on LinkedIn][💖🖇linkedin-img]][💖🖇linkedin] [![Follow Me on Ruby.Social][💖🐘ruby-mast-img]][💖🐘ruby-mast] [![Follow Me on Bluesky][💖🦋bluesky-img]][💖🦋bluesky] [![Contact Maintainer][🚂maint-contact-img]][🚂maint-contact] [![My technical writing][💖💁🏼♂️devto-img]][💖💁🏼♂️devto] |
|
|
93
|
+
| `...` 💖 | [![Find Me on WellFound:][💖✌️wellfound-img]][💖✌️wellfound] [![Find Me on CrunchBase][💖💲crunchbase-img]][💖💲crunchbase] [![My LinkTree][💖🌳linktree-img]][💖🌳linktree] [![More About Me][💖💁🏼♂️aboutme-img]][💖💁🏼♂️aboutme] [🧊][💖🧊berg] [🐙][💖🐙hub] [🛖][💖🛖hut] [🧪][💖🧪lab] |
|
|
94
|
+
|
|
95
|
+
### Compatibility
|
|
96
|
+
|
|
97
|
+
Compatible with MRI Ruby 4.0.0+, and concordant releases of JRuby, and TruffleRuby.
|
|
98
|
+
CI workflows and Appraisals are generated for MRI Ruby 4.0.0+.
|
|
99
|
+
This test floor is configured by `ruby.test_minimum` in `.kettle-jem.yml` and
|
|
100
|
+
may be higher than the gem's runtime compatibility floor when legacy Rubies are
|
|
101
|
+
not practical for the current toolchain.
|
|
102
|
+
|
|
103
|
+
<a href="https://github.com/kettle-dev"><img alt="kettle-dev Logo by Aboling0, CC BY-SA 4.0" src="https://logos.galtzo.com/assets/images/kettle-dev/avatar-128px.svg" width="14%" align="right"/></a>
|
|
104
|
+
|
|
105
|
+
The _amazing_ test matrix is powered by the kettle-dev stack.
|
|
106
|
+
|
|
107
|
+
<details markdown="1">
|
|
108
|
+
<summary>How kettle-dev manages complexity in tests</summary>
|
|
109
|
+
|
|
110
|
+
| Gem | Source | Role | Total downloads |
|
|
111
|
+
|-----|--------|------|---------------------|
|
|
112
|
+
| [appraisal2](https://clickgems.clickhouse.com/dashboard/appraisal2) | [GitHub](https://github.com/appraisal-rb/appraisal2) | multi-dependency Appraisal matrix generation | [](https://clickgems.clickhouse.com/dashboard/appraisal2) |
|
|
113
|
+
| [appraisal2-rubocop](https://clickgems.clickhouse.com/dashboard/appraisal2-rubocop) | [GitHub](https://github.com/appraisal-rb/appraisal2-rubocop) | RuboCop Appraisal generator integration | [](https://clickgems.clickhouse.com/dashboard/appraisal2-rubocop) |
|
|
114
|
+
| [kettle-dev](https://clickgems.clickhouse.com/dashboard/kettle-dev) | [GitHub](https://github.com/kettle-dev/kettle-dev) | development, release, and CI workflow tooling | [](https://clickgems.clickhouse.com/dashboard/kettle-dev) |
|
|
115
|
+
| [kettle-jem](https://clickgems.clickhouse.com/dashboard/kettle-jem) | [GitHub](https://github.com/kettle-dev/kettle-jem) | Appraisals & CI workflow templates | [](https://clickgems.clickhouse.com/dashboard/kettle-jem) |
|
|
116
|
+
| [kettle-soup-cover](https://clickgems.clickhouse.com/dashboard/kettle-soup-cover) | [GitHub](https://github.com/kettle-dev/kettle-soup-cover) | SimpleCov coverage policy and reporting | [](https://clickgems.clickhouse.com/dashboard/kettle-soup-cover) |
|
|
117
|
+
| [kettle-test](https://clickgems.clickhouse.com/dashboard/kettle-test) | [GitHub](https://github.com/kettle-dev/kettle-test) | standard test runner and coverage harness | [](https://clickgems.clickhouse.com/dashboard/kettle-test) |
|
|
118
|
+
| [rubocop-lts](https://clickgems.clickhouse.com/dashboard/rubocop-lts) | [GitHub](https://github.com/rubocop-lts/rubocop-lts) | Ruby-version-aware linting | [](https://clickgems.clickhouse.com/dashboard/rubocop-lts) |
|
|
119
|
+
| [turbo_tests2](https://clickgems.clickhouse.com/dashboard/turbo_tests2) | [GitHub](https://github.com/galtzo-floss/turbo_tests2) | parallel test execution | [](https://clickgems.clickhouse.com/dashboard/turbo_tests2) |
|
|
120
|
+
|
|
121
|
+
</details>
|
|
122
|
+
|
|
123
|
+
## ✨ Installation
|
|
124
|
+
|
|
125
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
126
|
+
|
|
127
|
+
```console
|
|
128
|
+
bundle add psych-merge
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
132
|
+
|
|
133
|
+
```console
|
|
134
|
+
gem install psych-merge
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## ⚙️ Configuration
|
|
138
|
+
|
|
139
|
+
### Signature Match Preference
|
|
140
|
+
|
|
141
|
+
Control which version to use when nodes have matching signatures but different content:
|
|
142
|
+
|
|
143
|
+
```ruby
|
|
144
|
+
# Use template version (for config updates)
|
|
145
|
+
merger = Psych::Merge::SmartMerger.new(
|
|
146
|
+
template,
|
|
147
|
+
destination,
|
|
148
|
+
preference: :template,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# Use destination version (default - preserve customizations)
|
|
152
|
+
merger = Psych::Merge::SmartMerger.new(
|
|
153
|
+
template,
|
|
154
|
+
destination,
|
|
155
|
+
preference: :destination,
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Template-Only Nodes
|
|
160
|
+
|
|
161
|
+
Control whether to add nodes that only exist in the template:
|
|
162
|
+
|
|
163
|
+
```ruby
|
|
164
|
+
# Add template-only nodes
|
|
165
|
+
merger = Psych::Merge::SmartMerger.new(
|
|
166
|
+
template,
|
|
167
|
+
destination,
|
|
168
|
+
add_template_only_nodes: true,
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Custom Freeze Token
|
|
173
|
+
|
|
174
|
+
Use a custom freeze token to avoid conflicts with other tools:
|
|
175
|
+
|
|
176
|
+
```ruby
|
|
177
|
+
merger = Psych::Merge::SmartMerger.new(
|
|
178
|
+
template,
|
|
179
|
+
destination,
|
|
180
|
+
freeze_token: "my-project",
|
|
181
|
+
)
|
|
182
|
+
# Now looks for: # my-project:freeze and # my-project:unfreeze
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Mapping Match Refiner
|
|
186
|
+
|
|
187
|
+
When YAML mapping entries (key-value pairs) don't match by exact key name, the
|
|
188
|
+
`MappingMatchRefiner` uses fuzzy matching to pair entries with:
|
|
189
|
+
|
|
190
|
+
- Similar key names (e.g., `database_url` vs `db_url`)
|
|
191
|
+
- Keys with typos or naming convention differences
|
|
192
|
+
- Renamed keys that contain similar values
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
# Enable mapping fuzzy matching
|
|
196
|
+
merger = Psych::Merge::SmartMerger.new(
|
|
197
|
+
template,
|
|
198
|
+
destination,
|
|
199
|
+
match_refiners: [
|
|
200
|
+
Psych::Merge::MappingMatchRefiner.new(threshold: 0.5),
|
|
201
|
+
],
|
|
202
|
+
)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### MappingMatchRefiner Options
|
|
206
|
+
|
|
207
|
+
| Option | Default | Description |
|
|
208
|
+
|--------|---------|-------------|
|
|
209
|
+
| `threshold` | 0.5 | Minimum similarity score (0.0-1.0) to accept a match |
|
|
210
|
+
| `key_weight` | 0.7 | Weight for key name similarity |
|
|
211
|
+
| `value_weight` | 0.3 | Weight for value similarity |
|
|
212
|
+
|
|
213
|
+
```ruby
|
|
214
|
+
# Custom weights for key-centric matching
|
|
215
|
+
refiner = Psych::Merge::MappingMatchRefiner.new(
|
|
216
|
+
threshold: 0.6,
|
|
217
|
+
key_weight: 0.8, # Focus more on key names
|
|
218
|
+
value_weight: 0.2, # Less focus on values
|
|
219
|
+
)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Debug Logging
|
|
223
|
+
|
|
224
|
+
Enable debug logging to see merge decisions:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
export PSYCH_MERGE_DEBUG=1
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## 🔧 Basic Usage
|
|
231
|
+
|
|
232
|
+
### Merging Two YAML Files
|
|
233
|
+
|
|
234
|
+
```ruby
|
|
235
|
+
require "psych/merge"
|
|
236
|
+
|
|
237
|
+
template_content = File.read("template.yml")
|
|
238
|
+
dest_content = File.read("destination.yml")
|
|
239
|
+
|
|
240
|
+
merger = Psych::Merge::SmartMerger.new(template_content, dest_content)
|
|
241
|
+
result = merger.merge
|
|
242
|
+
|
|
243
|
+
File.write("merged.yml", result.to_yaml)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Analyzing a YAML File
|
|
247
|
+
|
|
248
|
+
```ruby
|
|
249
|
+
require "psych/merge"
|
|
250
|
+
|
|
251
|
+
source = File.read("config.yml")
|
|
252
|
+
analysis = Psych::Merge::FileAnalysis.new(source)
|
|
253
|
+
|
|
254
|
+
# Iterate over all top-level nodes
|
|
255
|
+
analysis.statements.each do |node|
|
|
256
|
+
sig = analysis.generate_signature(node)
|
|
257
|
+
puts "#{node.class}: #{sig.inspect}"
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# Get freeze blocks
|
|
261
|
+
analysis.freeze_blocks.each do |freeze_node|
|
|
262
|
+
puts "Protected: lines #{freeze_node.start_line}-#{freeze_node.end_line}"
|
|
263
|
+
end
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Fuzzy Key Matching
|
|
267
|
+
|
|
268
|
+
When keys are renamed between template and destination, use the `MappingMatchRefiner`:
|
|
269
|
+
|
|
270
|
+
```ruby
|
|
271
|
+
require "psych/merge"
|
|
272
|
+
|
|
273
|
+
template = <<~YAML
|
|
274
|
+
database_url: postgres://localhost/app
|
|
275
|
+
cache_ttl: 3600
|
|
276
|
+
api_endpoint: https://api.example.com
|
|
277
|
+
YAML
|
|
278
|
+
|
|
279
|
+
destination = <<~YAML
|
|
280
|
+
db_url: postgres://localhost/custom
|
|
281
|
+
cache_timeout: 7200
|
|
282
|
+
service_endpoint: https://custom.example.com
|
|
283
|
+
YAML
|
|
284
|
+
|
|
285
|
+
# Default merge won't match keys (names differ)
|
|
286
|
+
# Use MappingMatchRefiner for fuzzy matching
|
|
287
|
+
merger = Psych::Merge::SmartMerger.new(
|
|
288
|
+
template,
|
|
289
|
+
destination,
|
|
290
|
+
match_refiners: [
|
|
291
|
+
Psych::Merge::MappingMatchRefiner.new(threshold: 0.5),
|
|
292
|
+
],
|
|
293
|
+
)
|
|
294
|
+
result = merger.merge
|
|
295
|
+
|
|
296
|
+
# Keys are matched despite name differences:
|
|
297
|
+
# - database_url ↔ db_url (similar: "database" ~ "db")
|
|
298
|
+
# - cache_ttl ↔ cache_timeout (similar: "ttl" ~ "timeout")
|
|
299
|
+
# - api_endpoint ↔ service_endpoint (similar: "endpoint")
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Freeze Block Example
|
|
303
|
+
|
|
304
|
+
```yaml
|
|
305
|
+
# Application configuration
|
|
306
|
+
app_name: MyApp
|
|
307
|
+
|
|
308
|
+
# psych-merge:freeze Secret configuration
|
|
309
|
+
database:
|
|
310
|
+
host: production-db.example.com
|
|
311
|
+
password: super-secret-password
|
|
312
|
+
# psych-merge:unfreeze
|
|
313
|
+
|
|
314
|
+
logging:
|
|
315
|
+
level: info
|
|
316
|
+
format: json
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## 🔐 Security
|
|
320
|
+
|
|
321
|
+
See [SECURITY.md][🔐security].
|
|
322
|
+
|
|
323
|
+
## 🤝 Contributing
|
|
324
|
+
|
|
325
|
+
If you need some ideas of where to help, you could work on adding more code coverage,
|
|
326
|
+
or if it is already 💯 (see [below](#code-coverage)) check [issues][🤝gh-issues] or [PRs][🤝gh-pulls],
|
|
327
|
+
or use the gem and think about how it could be better.
|
|
328
|
+
|
|
329
|
+
We [![Keep A Changelog][📗keep-changelog-img]][📗keep-changelog] so if you make changes, remember to update it.
|
|
330
|
+
|
|
331
|
+
See [CONTRIBUTING.md][🤝contributing] for more detailed instructions.
|
|
332
|
+
|
|
333
|
+
### Code Coverage
|
|
334
|
+
|
|
335
|
+
<details markdown="1">
|
|
336
|
+
<summary>Coverage service badges</summary>
|
|
337
|
+
|
|
338
|
+
</details>
|
|
339
|
+
|
|
340
|
+
## 📌 Versioning
|
|
341
|
+
|
|
342
|
+
This library follows [![Semantic Versioning 2.0.0][📌semver-img]][📌semver] for its public API where practical.
|
|
343
|
+
For most applications, prefer the [Pessimistic Version Constraint][📌pvc] with two digits of precision.
|
|
344
|
+
|
|
345
|
+
For example:
|
|
346
|
+
|
|
347
|
+
```ruby
|
|
348
|
+
spec.add_dependency("psych-merge", "~> 7.0")
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
<details markdown="1">
|
|
352
|
+
<summary>📌 Is "Platform Support" part of the public API? More details inside.</summary>
|
|
353
|
+
|
|
354
|
+
Dropping support for a platform can be a breaking change for affected users.
|
|
355
|
+
If a release changes supported platforms, it should be called out clearly in the changelog and versioned with that impact in mind.
|
|
356
|
+
|
|
357
|
+
To get a better understanding of how SemVer is intended to work over a project's lifetime,
|
|
358
|
+
read this article from the creator of SemVer:
|
|
359
|
+
|
|
360
|
+
- ["Major Version Numbers are Not Sacred"][📌major-versions-not-sacred]
|
|
361
|
+
|
|
362
|
+
</details>
|
|
363
|
+
|
|
364
|
+
See [CHANGELOG.md][📌changelog] for a list of releases.
|
|
365
|
+
|
|
366
|
+
## 📄 License
|
|
367
|
+
|
|
368
|
+
The gem is available under the following licenses: [AGPL-3.0-only](https://github.com/structuredmerge/structuredmerge-ruby/blob/main/AGPL-3.0-only.md), [PolyForm-Small-Business-1.0.0](https://github.com/structuredmerge/structuredmerge-ruby/blob/main/PolyForm-Small-Business-1.0.0.md).
|
|
369
|
+
See [LICENSE.md][📄license] for details.
|
|
370
|
+
|
|
371
|
+
If none of the available licenses suit your use case, please [contact us](mailto:floss@galtzo.com) to discuss a custom commercial license.
|
|
372
|
+
|
|
373
|
+
[⛳liberapay-img]: https://img.shields.io/liberapay/goal/pboling.svg?logo=liberapay&color=a51611&style=flat
|
|
374
|
+
[⛳liberapay-bottom-img]: https://img.shields.io/liberapay/goal/pboling.svg?style=for-the-badge&logo=liberapay&color=a51611
|
|
375
|
+
[⛳liberapay]: https://liberapay.com/pboling/donate
|
|
376
|
+
[🖇sponsor-img]: https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github
|
|
377
|
+
[🖇sponsor-bottom-img]: https://img.shields.io/badge/Sponsor_Me!-pboling-blue?style=for-the-badge&logo=github
|
|
378
|
+
[🖇sponsor]: https://github.com/sponsors/pboling
|
|
379
|
+
[🖇kofi-img]: https://img.shields.io/badge/ko--fi-%E2%9C%93-a51611.svg?style=flat
|
|
380
|
+
[🖇kofi]: https://ko-fi.com/pboling
|
|
381
|
+
[🖇buyme-small-img]: https://img.shields.io/badge/buy_me_a_coffee-%E2%9C%93-a51611.svg?style=flat
|
|
382
|
+
[🖇buyme-img]: https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20latte&emoji=&slug=pboling&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff
|
|
383
|
+
[🖇buyme]: https://www.buymeacoffee.com/pboling
|
|
384
|
+
[🖇paypal-img]: https://img.shields.io/badge/donate-paypal-a51611.svg?style=flat&logo=paypal
|
|
385
|
+
[🖇paypal-bottom-img]: https://img.shields.io/badge/donate-paypal-a51611.svg?style=for-the-badge&logo=paypal&color=0A0A0A
|
|
386
|
+
[🖇paypal]: https://www.paypal.com/paypalme/peterboling
|
|
387
|
+
[🖇floss-funding.dev]: https://floss-funding.dev
|
|
388
|
+
[🖇floss-funding-gem]: https://github.com/galtzo-floss/floss_funding
|
|
389
|
+
[✉️discord-invite]: https://discord.gg/3qme4XHNKN
|
|
390
|
+
[✉️discord-invite-img-ftb]: https://img.shields.io/discord/1373797679469170758?style=for-the-badge&logo=discord
|
|
391
|
+
[✉️ruby-friends-img]: https://img.shields.io/badge/daily.dev-%F0%9F%92%8E_Ruby_Friends-0A0A0A?style=for-the-badge&logo=dailydotdev&logoColor=white
|
|
392
|
+
[✉️ruby-friends]: https://app.daily.dev/squads/rubyfriends
|
|
393
|
+
[✉️ruby-forum-top-img]: https://img.shields.io/discourse/topics?server=https%3A%2F%2Fwww.rubyforum.org&style=flat&logo=discourse&label=Ruby%20Users%20Forum
|
|
394
|
+
[✉️ruby-forum-img]: https://img.shields.io/discourse/topics?server=https%3A%2F%2Fwww.rubyforum.org&style=for-the-badge&logo=discourse&label=Ruby%20Users%20Forum
|
|
395
|
+
[✉️ruby-forum]: https://www.rubyforum.org/tag/structuredmerge
|
|
396
|
+
[✇bundle-group-pattern]: https://gist.github.com/pboling/4564780
|
|
397
|
+
[⛳️gem-namespace]: https://github.com/structuredmerge/structuredmerge-ruby/tree/main/gems/psych-merge
|
|
398
|
+
[⛳️namespace-img]: https://img.shields.io/badge/namespace-Psych::Merge-3C2D2D.svg?style=square&logo=ruby&logoColor=white
|
|
399
|
+
[⛳️gem-name]: https://clickgems.clickhouse.com/dashboard/psych-merge
|
|
400
|
+
[⛳️name-img]: https://img.shields.io/badge/name-psych--merge-3C2D2D.svg?style=square&logo=rubygems&logoColor=red
|
|
401
|
+
[⛳️tag-img]: https://img.shields.io/github/tag/structuredmerge/structuredmerge-ruby.svg
|
|
402
|
+
[⛳️tag]: https://github.com/structuredmerge/structuredmerge-ruby/releases
|
|
403
|
+
[🚂maint-blog]: http://www.railsbling.com/tags/psych-merge
|
|
404
|
+
[🚂maint-blog-img]: https://img.shields.io/badge/blog-railsbling-0093D0.svg?style=for-the-badge&logo=rubyonrails&logoColor=orange
|
|
405
|
+
[🚂maint-contact]: http://www.railsbling.com/contact
|
|
406
|
+
[🚂maint-contact-img]: https://img.shields.io/badge/Contact-Maintainer-0093D0.svg?style=flat&logo=rubyonrails&logoColor=red
|
|
407
|
+
[💖🖇linkedin]: http://www.linkedin.com/in/peterboling
|
|
408
|
+
[💖🖇linkedin-img]: https://img.shields.io/badge/LinkedIn-Profile-0B66C2?style=flat&logo=newjapanprowrestling
|
|
409
|
+
[💖✌️wellfound]: https://wellfound.com/u/peter-boling
|
|
410
|
+
[💖✌️wellfound-img]: https://img.shields.io/badge/peter--boling-orange?style=flat&logo=wellfound
|
|
411
|
+
[💖💲crunchbase]: https://www.crunchbase.com/person/peter-boling
|
|
412
|
+
[💖💲crunchbase-img]: https://img.shields.io/badge/peter--boling-purple?style=flat&logo=crunchbase
|
|
413
|
+
[💖🐘ruby-mast]: https://ruby.social/@galtzo
|
|
414
|
+
[💖🐘ruby-mast-img]: https://img.shields.io/mastodon/follow/109447111526622197?domain=https://ruby.social&style=flat&logo=mastodon&label=Ruby%20@galtzo
|
|
415
|
+
[💖🦋bluesky]: https://bsky.app/profile/galtzo.com
|
|
416
|
+
[💖🦋bluesky-img]: https://img.shields.io/badge/@galtzo.com-0285FF?style=flat&logo=bluesky&logoColor=white
|
|
417
|
+
[💖🌳linktree]: https://linktr.ee/galtzo
|
|
418
|
+
[💖🌳linktree-img]: https://img.shields.io/badge/galtzo-purple?style=flat&logo=linktree
|
|
419
|
+
[💖💁🏼♂️devto]: https://dev.to/galtzo
|
|
420
|
+
[💖💁🏼♂️devto-img]: https://img.shields.io/badge/dev.to-0A0A0A?style=flat&logo=devdotto&logoColor=white
|
|
421
|
+
[💖💁🏼♂️aboutme]: https://about.me/peter.boling
|
|
422
|
+
[💖💁🏼♂️aboutme-img]: https://img.shields.io/badge/about.me-0A0A0A?style=flat&logo=aboutme&logoColor=white
|
|
423
|
+
[💖🧊berg]: https://codeberg.org/pboling
|
|
424
|
+
[💖🐙hub]: https://github.org/pboling
|
|
425
|
+
[💖🛖hut]: https://sr.ht/~galtzo/
|
|
426
|
+
[💖🧪lab]: https://gitlab.com/pboling
|
|
427
|
+
[👨🏼🏫expsup-upwork]: https://www.upwork.com/freelancers/~014942e9b056abdf86?mp_source=share
|
|
428
|
+
[👨🏼🏫expsup-upwork-img]: https://img.shields.io/badge/UpWork-13544E?style=for-the-badge&logo=Upwork&logoColor=white
|
|
429
|
+
[👨🏼🏫expsup-codementor]: https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github
|
|
430
|
+
[👨🏼🏫expsup-codementor-img]: https://img.shields.io/badge/CodeMentor-Get_Help-1abc9c?style=for-the-badge&logo=CodeMentor&logoColor=white
|
|
431
|
+
[🏙️entsup-tidelift]: https://tidelift.com/subscription/pkg/rubygems-psych-merge?utm_source=rubygems-psych-merge&utm_medium=referral&utm_campaign=readme
|
|
432
|
+
[🏙️entsup-tidelift-img]: https://img.shields.io/badge/Tidelift_and_Sonar-Enterprise_Support-FD3456?style=for-the-badge&logo=sonar&logoColor=white
|
|
433
|
+
[🏙️entsup-tidelift-sonar]: https://blog.tidelift.com/tidelift-joins-sonar
|
|
434
|
+
[💁🏼♂️peterboling]: http://www.peterboling.com
|
|
435
|
+
[🚂railsbling]: http://www.railsbling.com
|
|
436
|
+
[📜src-gl-img]: https://img.shields.io/badge/GitLab-FBA326?style=for-the-badge&logo=Gitlab&logoColor=orange
|
|
437
|
+
[📜src-gl]: https://gitlab.com/structuredmerge/structuredmerge-ruby/-/tree/main/gems/psych-merge
|
|
438
|
+
[📜src-cb-img]: https://img.shields.io/badge/CodeBerg-4893CC?style=for-the-badge&logo=CodeBerg&logoColor=blue
|
|
439
|
+
[📜src-cb]: https://codeberg.org/structuredmerge/structuredmerge-ruby/src/branch/main/gems/psych-merge
|
|
440
|
+
[📜src-gh-img]: https://img.shields.io/badge/GitHub-238636?style=for-the-badge&logo=GitHub&logoColor=green
|
|
441
|
+
[📜src-gh]: https://github.com/structuredmerge/structuredmerge-ruby/tree/main/gems/psych-merge
|
|
442
|
+
[📜docs-cr-rd-img]: https://img.shields.io/badge/RubyDoc-Current_Release-943CD2?style=for-the-badge&logo=readthedocs&logoColor=white
|
|
443
|
+
[📜docs-head-rd-img]: https://img.shields.io/badge/YARD_on_Galtzo.com-HEAD-943CD2?style=for-the-badge&logo=readthedocs&logoColor=white
|
|
444
|
+
[📜gl-wiki]: https://gitlab.com/structuredmerge/structuredmerge-ruby/-/wikis/home
|
|
445
|
+
[📜gh-wiki]: https://github.com/structuredmerge/structuredmerge-ruby/wiki
|
|
446
|
+
[📜gl-wiki-img]: https://img.shields.io/badge/wiki-gitlab-943CD2.svg?style=for-the-badge&logo=gitlab&logoColor=white
|
|
447
|
+
[📜gh-wiki-img]: https://img.shields.io/badge/wiki-github-943CD2.svg?style=for-the-badge&logo=github&logoColor=white
|
|
448
|
+
[👽dl-rank]: https://clickgems.clickhouse.com/dashboard/psych-merge
|
|
449
|
+
[👽dl-ranki]: https://img.shields.io/gem/dt/psych-merge.svg
|
|
450
|
+
[👽version]: https://clickgems.clickhouse.com/dashboard/psych-merge
|
|
451
|
+
[👽versioni]: https://img.shields.io/gem/v/psych-merge.svg
|
|
452
|
+
[🚎11-c-wf]: https://github.com/structuredmerge/structuredmerge-ruby/actions/workflows/current.yml
|
|
453
|
+
[🚎11-c-wfi]: https://github.com/structuredmerge/structuredmerge-ruby/actions/workflows/current.yml/badge.svg
|
|
454
|
+
[💎ruby-c-i]: https://img.shields.io/badge/Ruby-current-CC342D?style=for-the-badge&logo=ruby&logoColor=green
|
|
455
|
+
[🤝gh-issues]: https://github.com/structuredmerge/structuredmerge-ruby/issues
|
|
456
|
+
[🤝gh-pulls]: https://github.com/structuredmerge/structuredmerge-ruby/pulls
|
|
457
|
+
[🤝gl-issues]: https://gitlab.com/structuredmerge/structuredmerge-ruby/-/issues
|
|
458
|
+
[🤝gl-pulls]: https://gitlab.com/structuredmerge/structuredmerge-ruby/-/merge_requests
|
|
459
|
+
[🤝cb-issues]: https://codeberg.org/structuredmerge/structuredmerge-ruby/issues
|
|
460
|
+
[🤝cb-pulls]: https://codeberg.org/structuredmerge/structuredmerge-ruby/pulls
|
|
461
|
+
[🤝cb-donate]: https://donate.codeberg.org/
|
|
462
|
+
[🤝contributing]: https://github.com/structuredmerge/structuredmerge-ruby/blob/main/CONTRIBUTING.md
|
|
463
|
+
[🖐contrib-rocks]: https://contrib.rocks
|
|
464
|
+
[🖐contributors]: https://github.com/structuredmerge/structuredmerge-ruby/graphs/contributors
|
|
465
|
+
[🖐contributors-img]: https://contrib.rocks/image?repo=structuredmerge/structuredmerge-ruby
|
|
466
|
+
[🪇conduct]: https://github.com/structuredmerge/structuredmerge-ruby/blob/main/CODE_OF_CONDUCT.md
|
|
467
|
+
[🪇conduct-img]: https://img.shields.io/badge/Contributor_Covenant-2.1-259D6C.svg
|
|
468
|
+
[📌pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|
|
469
|
+
[📌semver]: https://semver.org/spec/v2.0.0.html
|
|
470
|
+
[📌semver-img]: https://img.shields.io/badge/semver-2.0.0-259D6C.svg?style=flat
|
|
471
|
+
[📌semver-breaking]: https://github.com/semver/semver/issues/716#issuecomment-869336139
|
|
472
|
+
[📌major-versions-not-sacred]: https://tom.preston-werner.com/2022/05/23/major-version-numbers-are-not-sacred.html
|
|
473
|
+
[📌changelog]: https://github.com/structuredmerge/structuredmerge-ruby/blob/main/CHANGELOG.md
|
|
474
|
+
[📗keep-changelog]: https://keepachangelog.com/en/1.0.0/
|
|
475
|
+
[📗keep-changelog-img]: https://img.shields.io/badge/keep--a--changelog-1.0.0-34495e.svg?style=flat
|
|
476
|
+
[📌gitmoji]: https://gitmoji.dev
|
|
477
|
+
[📌gitmoji-img]: https://img.shields.io/badge/gitmoji_commits-%20%F0%9F%98%9C%20%F0%9F%98%8D-34495e.svg?style=flat-square
|
|
478
|
+
[🧮kloc]: https://www.youtube.com/watch?v=dQw4w9WgXcQ
|
|
479
|
+
[🧮kloc-img]: https://img.shields.io/badge/KLOC-2.008-FFDD67.svg?style=for-the-badge&logo=YouTube&logoColor=blue
|
|
480
|
+
[🔐security]: https://github.com/structuredmerge/structuredmerge-ruby/blob/main/SECURITY.md
|
|
481
|
+
[🔐security-img]: https://img.shields.io/badge/security-policy-259D6C.svg?style=flat
|
|
482
|
+
[📄copyright-notice-explainer]: https://opensource.stackexchange.com/questions/5778/why-do-licenses-such-as-the-mit-license-specify-a-single-year
|
|
483
|
+
[📄license]: LICENSE.md
|
|
484
|
+
[📄license-ref]: LICENSE.md
|
|
485
|
+
[📄license-img]: https://img.shields.io/badge/License-AGPL--3.0--only_OR_PolyForm--Small--Business--1.0.0-259D6C.svg
|
|
486
|
+
[📄license-compat]: https://www.apache.org/legal/resolved.html#category-x
|
|
487
|
+
[📄license-compat-img]: https://img.shields.io/badge/Apache_Incompatible:_Category_X-%E2%9C%97-C0392B.svg?style=flat&logo=Apache
|
|
488
|
+
[📄ilo-declaration]: https://www.ilo.org/declaration/lang--en/index.htm
|
|
489
|
+
[📄ilo-declaration-img]: https://img.shields.io/badge/ILO_Fundamental_Principles-✓-259D6C.svg?style=flat
|
|
490
|
+
[🚎yard-current]: http://rubydoc.info/gems/psych-merge
|
|
491
|
+
[🚎yard-head]: https://psych-merge.galtzo.com
|
|
492
|
+
[💎stone_checksums]: https://github.com/galtzo-floss/stone_checksums
|
|
493
|
+
[💎SHA_checksums]: https://gitlab.com/structuredmerge/structuredmerge-ruby/-/tree/main/checksums
|
|
494
|
+
[💎rlts]: https://github.com/rubocop-lts/rubocop-lts
|
|
495
|
+
[💎rlts-img]: https://img.shields.io/badge/code_style_&_linting-rubocop--lts-34495e.svg?plastic&logo=ruby&logoColor=white
|
|
496
|
+
[💎appraisal2]: https://github.com/appraisal-rb/appraisal2
|
|
497
|
+
[💎appraisal2-img]: https://img.shields.io/badge/appraised_by-appraisal2-34495e.svg?plastic&logo=ruby&logoColor=white
|
|
498
|
+
[💎d-in-dvcs]: https://railsbling.com/posts/dvcs/put_the_d_in_dvcs/
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Psych
|
|
4
|
+
module Merge
|
|
5
|
+
# Extracts and tracks comments with their line numbers from YAML source.
|
|
6
|
+
# YAML comments use the same # syntax as Ruby, making freeze block detection
|
|
7
|
+
# straightforward.
|
|
8
|
+
#
|
|
9
|
+
# Inherits shared lookup, query, region-building, and attachment API from
|
|
10
|
+
# +Ast::Merge::Comment::HashTrackerBase+. Only format-specific comment
|
|
11
|
+
# extraction and owner resolution are overridden here.
|
|
12
|
+
#
|
|
13
|
+
# @example Basic usage
|
|
14
|
+
# tracker = CommentTracker.new(yaml_source)
|
|
15
|
+
# tracker.comments # => [{line: 1, indent: 0, text: "This is a comment"}]
|
|
16
|
+
# tracker.comment_at(1) # => {line: 1, indent: 0, text: "This is a comment"}
|
|
17
|
+
#
|
|
18
|
+
# @example Comment types
|
|
19
|
+
# # Full-line comment
|
|
20
|
+
# key: value # Inline comment
|
|
21
|
+
class CommentTracker < Ast::Merge::Comment::HashTrackerBase
|
|
22
|
+
# Initialize comment tracker by scanning the source
|
|
23
|
+
#
|
|
24
|
+
# @param source [String] YAML source code
|
|
25
|
+
def initialize(source)
|
|
26
|
+
@source = source
|
|
27
|
+
@line_parser = Ast::Merge::Comment::QuotedHashLineParser.new
|
|
28
|
+
super(source.lines.map(&:chomp))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def extract_comments
|
|
34
|
+
comments = []
|
|
35
|
+
|
|
36
|
+
@lines.each_with_index do |line, idx|
|
|
37
|
+
line_num = idx + 1
|
|
38
|
+
parsed = @line_parser.parse(line)
|
|
39
|
+
next unless parsed
|
|
40
|
+
|
|
41
|
+
if parsed.full_line?
|
|
42
|
+
comments << {
|
|
43
|
+
line: line_num,
|
|
44
|
+
indent: parsed.indent,
|
|
45
|
+
text: parsed.text,
|
|
46
|
+
full_line: true,
|
|
47
|
+
raw: parsed.raw
|
|
48
|
+
}
|
|
49
|
+
elsif parsed.inline?
|
|
50
|
+
comments << {
|
|
51
|
+
line: line_num,
|
|
52
|
+
indent: parsed.column,
|
|
53
|
+
text: parsed.text,
|
|
54
|
+
full_line: false,
|
|
55
|
+
raw: parsed.raw
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
comments
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def owner_line_num(owner)
|
|
64
|
+
return owner.start_line if owner.respond_to?(:start_line) && owner.start_line
|
|
65
|
+
if owner.respond_to?(:key) && owner.key&.respond_to?(:start_line) && owner.key.start_line
|
|
66
|
+
return owner.key.start_line
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
nil
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|