forked from shakacode/react_on_rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require_relative "version" | ||
|
||
class VersionSyntaxConverter | ||
def rubygem_to_npm(rubygem_version) | ||
rubygem_version ||= ReactOnRails::VERSION | ||
regex_match = rubygem_version.match(/(\d+\.\d+\.\d+)[.\-]?(.+)?/) | ||
if regex_match[2] | ||
return "#{regex_match[1]}-#{regex_match[2]}" | ||
else | ||
return "#{regex_match[1]}" | ||
end | ||
end | ||
|
||
def npm_to_rubygem(npm_version) | ||
match = npm_version | ||
.tr("-", ".") | ||
.strip | ||
.match(/(\d.*)/) | ||
match.present? ? match[0] : nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
spec/react_on_rails/generators/version_syntax_converter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require_relative "../simplecov_helper" | ||
require_relative "../spec_helper" | ||
require_relative "../support/version_test_helpers" | ||
require_relative "../../../lib/react_on_rails/version_syntax_converter" | ||
|
||
RSpec.describe VersionSyntaxConverter do | ||
subject(:converter) { VersionSyntaxConverter.new } | ||
|
||
describe "#rubygem_to_npm" do | ||
context "when gem version is 1.0.0" do | ||
specify { expect(converter.rubygem_to_npm("1.0.0")).to eq "1.0.0" } | ||
end | ||
|
||
context "when gem version is 10.20.30.rc.4" do | ||
specify { expect(converter.rubygem_to_npm("10.20.30.rc.4")).to eq "10.20.30-rc.4" } | ||
end | ||
end | ||
|
||
describe "#npm_to_rubygem" do | ||
context "with an npm version of '0.0.2'" do | ||
specify { expect(converter.npm_to_rubygem("0.0.2")).to eq("0.0.2") } | ||
end | ||
|
||
context "with an npm version of '^14.0.0-beta.2'" do | ||
specify { expect(converter.npm_to_rubygem("^14.0.0-beta.2")).to eq("14.0.0.beta.2") } | ||
end | ||
|
||
context "with an npm version of '../../..'" do | ||
specify { expect(converter.npm_to_rubygem("../../..")).to be_nil } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def stub_gem_version(version) | ||
stub_const("ReactOnRails::VERSION", version) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters