class ReactOnRails::VersionChecker
Responsible for checking versions of rubygem versus yarn node package against each other at runtime.
Constants
- MAJOR_MINOR_PATCH_VERSION_REGEX
Attributes
Public Class Methods
Source
# File lib/react_on_rails/version_checker.rb, line 11 def self.build new(NodePackageVersion.build) end
Source
# File lib/react_on_rails/version_checker.rb, line 15 def initialize(node_package_version) @node_package_version = node_package_version end
Public Instance Methods
Source
# File lib/react_on_rails/version_checker.rb, line 22 def log_if_gem_and_node_package_versions_differ return if node_package_version.raw.nil? || node_package_version.local_path_or_url? return log_node_semver_version_warning if node_package_version.semver_wildcard? node_major_minor_patch = node_package_version.major_minor_patch gem_major_minor_patch = gem_major_minor_patch_version versions_match = node_major_minor_patch[0] == gem_major_minor_patch[0] && node_major_minor_patch[1] == gem_major_minor_patch[1] && node_major_minor_patch[2] == gem_major_minor_patch[2] log_differing_versions_warning unless versions_match end
For compatibility, the gem and the node package versions should always match, unless the user really knows what they’re doing. So we will give a warning if they do not.
Private Instance Methods
Source
# File lib/react_on_rails/version_checker.rb, line 37 def common_error_msg <<-MSG.strip_heredoc Detected: #{node_package_version.raw} gem: #{gem_version} Ensure the installed version of the gem is the same as the version of your installed node package. Do not use >= or ~> in your Gemfile for react_on_rails. Do not use ^ or ~ in your package.json for react-on-rails. Run `yarn add react-on-rails --exact` in the directory containing folder node_modules. MSG end
Source
# File lib/react_on_rails/version_checker.rb, line 63 def gem_major_minor_patch_version match = gem_version.match(MAJOR_MINOR_PATCH_VERSION_REGEX) [match[1], match[2], match[3]] end
Source
# File lib/react_on_rails/version_checker.rb, line 59 def gem_version ReactOnRails::VERSION end
Source
# File lib/react_on_rails/version_checker.rb, line 48 def log_differing_versions_warning msg = "**WARNING** ReactOnRails: ReactOnRails gem and node package versions do not match\n#{common_error_msg}" Rails.logger.warn(msg) end
Source
# File lib/react_on_rails/version_checker.rb, line 53 def log_node_semver_version_warning msg = "**WARNING** ReactOnRails: Your node package version for react-on-rails contains a " \ "^ or ~\n#{common_error_msg}" Rails.logger.warn(msg) end