Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix readme replacement #32

Merged
merged 1 commit into from Dec 12, 2023
Merged

Conversation

sj26
Copy link
Contributor

@sj26 sj26 commented Dec 9, 2023

The readme replacement currently appends the array of new lines instead of the lines themselves. Modifying to concatenating the array instead of appending it fixes there problem.

Found via an error when spinning up a branch on a schema_plus_triggers:

$ schema_dev bundle install
.../schema_dev-4.2.0/lib/schema_dev/readme.rb:68:in `!~': undefined method `=~' for ["As usual:\n", "\n", "```ruby\n", "gem \"<%= gem_name %>\"                # in a Gemfile\n", "gem.add_dependency \"<%= gem_name %>\" # in a .gemspec\n", "```\n"]:Array (NoMethodError)

  before = lines.take_while { |line| line !~ pattern }
                                          ^^
  from .../schema_dev-4.2.0/lib/schema_dev/readme.rb:68:in `block in replace_block'
  ...

Before

Without this, the first replacement causes lines to contain an array instead of only strings:

[
  ...,
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - begin -->\n",
  "<!-- These lines are auto-inserted from a schema_dev template -->\n",
  [
    "template line 1\n",
    "template line 2\n",
    ...
  ],
  "\n",
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - end -->\n",
  ...
]

After

lines remains an array of strings:

[
  ...,
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - begin -->\n",
  "<!-- These lines are auto-inserted from a schema_dev template -->\n",
  "template line 1\n",
  "template line 2\n",
  ...,
  "\n",
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - end -->\n",
  ...
]

Without this, lines becomes:

```
[
  ...,
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - begin -->\n",
  "<!-- These lines are auto-inserted from a schema_dev template -->\n",
  [
    "template line 1\n",
    "template line 2\n",
    ...
  ],
  "\n",
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - end -->\n",
  ...
]
```

Then subsequent replacements fail because they choke on the array in the
middle. Like:

```
.../schema_dev-4.2.0/lib/schema_dev/readme.rb:68:in `!~': undefined method `=~' for ["As usual:\n", "\n", "```ruby\n", "gem \"<%= gem_name %>\"                # in a Gemfile\n", "gem.add_dependency \"<%= gem_name %>\" # in a .gemspec\n", "```\n"]:Array (NoMethodError)

  before = lines.take_while { |line| line !~ pattern }
                                          ^^
  from .../schema_dev-4.2.0/lib/schema_dev/readme.rb:68:in `block in replace_block'
```

After this change:

```
[
  ...,
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - begin -->\n",
  "<!-- These lines are auto-inserted from a schema_dev template -->\n",
  "template line 1\n",
  "template line 2\n",
  ...,
  "\n",
  "<!-- SCHEMA_DEV: TEMPLATE #{key} - end -->\n",
  ...
]
```
@coveralls
Copy link

Coverage Status

coverage: 99.366% (+0.05%) from 99.32%
when pulling e0b3861 on sj26:fix-readme-replace-lines
into 014d579 on SchemaPlus:master.

@ronen ronen merged commit 8fcd930 into SchemaPlus:master Dec 12, 2023
18 checks passed
@ronen
Copy link
Member

ronen commented Dec 12, 2023

Hmm I wonder why that used to work?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants