File tree Expand file tree Collapse file tree 7 files changed +132
-1
lines changed Expand file tree Collapse file tree 7 files changed +132
-1
lines changed Original file line number Diff line number Diff line change 1+ nodejs 18.20.2
Original file line number Diff line number Diff line change 1+ exports [ 'Ruby README.md updateContent updates ruby version in README.md - 0.6.0-alpha.1 1' ] = `
2+ ## Install
3+
4+ \`\`\`ruby
5+ gem "sink", "~> 0.6.0.pre.alpha.1"
6+ \`\`\`
7+
8+ \`\`\`ruby
9+ gem "sink", "~> 0.6.0.pre.alpha.1"
10+ \`\`\`
11+
12+ \`\`\`ruby
13+ gem "sink", "~> 0.6.0.pre.alpha.1"
14+ \`\`\`
15+
16+ `
17+
18+ exports [ 'Ruby README.md updateContent updates ruby version in README.md - 0.6.0-beta.2 1' ] = `
19+ ## Install
20+
21+ \`\`\`ruby
22+ gem "sink", "~> 0.6.0.pre.beta.2"
23+ \`\`\`
24+
25+ \`\`\`ruby
26+ gem "sink", "~> 0.6.0.pre.beta.2"
27+ \`\`\`
28+
29+ \`\`\`ruby
30+ gem "sink", "~> 0.6.0.pre.beta.2"
31+ \`\`\`
32+
33+ `
34+
35+ exports [ 'Ruby README.md updateContent updates ruby version in README.md - 2.1.0 1' ] = `
36+ ## Install
37+
38+ \`\`\`ruby
39+ gem "sink", "~> 2.1.0"
40+ \`\`\`
41+
42+ \`\`\`ruby
43+ gem "sink", "~> 2.1.0"
44+ \`\`\`
45+
46+ \`\`\`ruby
47+ gem "sink", "~> 2.1.0"
48+ \`\`\`
49+
50+ `
Original file line number Diff line number Diff line change @@ -81,13 +81,20 @@ type ExtraTomlFile = {
8181 jsonpath : string ;
8282 glob ?: boolean ;
8383} ;
84+ type ExtraRubyReadMeFile = {
85+ type : 'ruby-readme' ;
86+ path : string ;
87+ jsonpath : string ;
88+ glob ?: boolean ;
89+ } ;
8490export type ExtraFile =
8591 | string
8692 | ExtraJsonFile
8793 | ExtraYamlFile
8894 | ExtraXmlFile
8995 | ExtraPomFile
90- | ExtraTomlFile ;
96+ | ExtraTomlFile
97+ | ExtraRubyReadMeFile ;
9198/**
9299 * These are configurations provided to each strategy per-path.
93100 */
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import {Generic} from '../updaters/generic';
4242import { GenericJson } from '../updaters/generic-json' ;
4343import { GenericXml } from '../updaters/generic-xml' ;
4444import { PomXml } from '../updaters/java/pom-xml' ;
45+ import { RubyReadMeUpdater } from '../updaters/ruby/readme' ;
4546import { GenericYaml } from '../updaters/generic-yaml' ;
4647import { GenericToml } from '../updaters/generic-toml' ;
4748import { FileNotFoundError } from '../errors' ;
@@ -553,6 +554,13 @@ If you instead want to use the version number \`${newVersion}\` generated from c
553554 updater : new PomXml ( version ) ,
554555 } ) ;
555556 break ;
557+ case 'ruby-readme' :
558+ extraFileUpdates . push ( {
559+ path : this . addPath ( path ) ,
560+ createIfMissing : false ,
561+ updater : new RubyReadMeUpdater ( { version} ) ,
562+ } ) ;
563+ break ;
556564 default :
557565 throw new Error (
558566 `unsupported extraFile type: ${
Original file line number Diff line number Diff line change 1+ import { DefaultUpdater } from '../default' ;
2+ import { RUBY_VERSION_REGEX , stringifyRubyVersion } from './common' ;
3+
4+ const RUBY_VERSION_LINE_REGEX = new RegExp (
5+ `(^gem "[^"]+"\\s*,\\s*"[^\\d]+)(${ RUBY_VERSION_REGEX . source } )(.)\\s*$` ,
6+ 'gm'
7+ ) ;
8+
9+ /**
10+ * Updates a versions.rb file which is expected to have a version string.
11+ */
12+ export class RubyReadMeUpdater extends DefaultUpdater {
13+ /**
14+ * Given initial file contents, return updated contents.
15+ * @param {string } content The initial content
16+ * @returns {string } The updated content
17+ */
18+ updateContent ( content : string ) : string {
19+ return content . replace (
20+ RUBY_VERSION_LINE_REGEX ,
21+ `$1${ stringifyRubyVersion ( this . version ) } "`
22+ ) ;
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ ## Install
2+
3+ ``` ruby
4+ gem " sink" , " ~> 0.2.0.pre.alpha"
5+ ```
6+
7+ ``` ruby
8+ gem " sink" , " ~> 0.2.0.pre.beta"
9+ ```
10+
11+ ``` ruby
12+ gem " sink" , " ~> 0.2.0"
13+ ```
Original file line number Diff line number Diff line change 1+ import { readFileSync } from 'fs' ;
2+ import { describe , it } from 'mocha' ;
3+ import { resolve } from 'path' ;
4+ import { RubyReadMeUpdater } from '../../src/updaters/ruby/readme' ;
5+ import { Version } from '../../src/version' ;
6+ import snapshot = require( 'snap-shot-it' ) ;
7+
8+ const fixturesPath = './test/updaters/fixtures' ;
9+
10+ describe ( 'Ruby README.md' , ( ) => {
11+ describe ( 'updateContent' , ( ) => {
12+ const versions = [ '2.1.0' , '0.6.0-alpha.1' , '0.6.0-beta.2' ] ;
13+
14+ for ( const ver of versions ) {
15+ it ( `updates ruby version in README.md - ${ ver } ` , async ( ) => {
16+ const oldContent = readFileSync (
17+ resolve ( fixturesPath , './README-ruby-version.md' ) ,
18+ 'utf8'
19+ ) . replace ( / \r \n / g, '\n' ) ;
20+ const version = new RubyReadMeUpdater ( {
21+ version : Version . parse ( ver ) ,
22+ } ) ;
23+ const newContent = version . updateContent ( oldContent ) ;
24+ snapshot ( newContent ) ;
25+ } ) ;
26+ }
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments