Class: ReactOnRails::VersionChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/react_on_rails/version_checker.rb

Overview

Responsible for checking versions of rubygem versus yarn node package against each other at runtime.

Defined Under Namespace

Classes: NodePackageVersion

Constant Summary collapse

VERSION_PARTS_REGEX =

Semver uses - to separate pre-release, but RubyGems use .

/(\d+)\.(\d+)\.(\d+)(?:[-.]([0-9A-Za-z.-]+))?/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_package_version) ⇒ VersionChecker

Returns a new instance of VersionChecker.



16
17
18
# File 'lib/react_on_rails/version_checker.rb', line 16

def initialize(node_package_version)
  @node_package_version = node_package_version
end

Instance Attribute Details

#node_package_versionObject (readonly)

Returns the value of attribute node_package_version.



7
8
9
# File 'lib/react_on_rails/version_checker.rb', line 7

def node_package_version
  @node_package_version
end

Class Method Details

.buildObject



12
13
14
# File 'lib/react_on_rails/version_checker.rb', line 12

def self.build
  new(NodePackageVersion.build)
end

Instance Method Details

#validate_version_and_package_compatibility!Object

Validates version and package compatibility. Raises ReactOnRails::Error if:

  • package.json file is not found

  • Both react-on-rails and react-on-rails-pro packages are installed

  • Pro gem is installed but using react-on-rails package

  • Pro package is installed but Pro gem is not installed

  • Non-exact version is used

  • Versions don’t match



28
29
30
31
32
33
# File 'lib/react_on_rails/version_checker.rb', line 28

def validate_version_and_package_compatibility!
  validate_package_json_exists!
  validate_package_gem_compatibility!
  validate_exact_version!
  validate_version_match!
end