Class: ReactOnRails::VersionChecker::NodePackageVersion
- Inherits:
-
Object
- Object
- ReactOnRails::VersionChecker::NodePackageVersion
- Defined in:
- lib/react_on_rails/version_checker.rb
Instance Attribute Summary collapse
-
#package_json ⇒ Object
readonly
Returns the value of attribute package_json.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(package_json) ⇒ NodePackageVersion
constructor
A new instance of NodePackageVersion.
- #major ⇒ Object
- #normalized ⇒ Object
- #raw ⇒ Object
- #relative_path? ⇒ Boolean
Constructor Details
#initialize(package_json) ⇒ NodePackageVersion
Returns a new instance of NodePackageVersion.
53 54 55 |
# File 'lib/react_on_rails/version_checker.rb', line 53 def initialize(package_json) @package_json = package_json end |
Instance Attribute Details
#package_json ⇒ Object (readonly)
Returns the value of attribute package_json.
43 44 45 |
# File 'lib/react_on_rails/version_checker.rb', line 43 def package_json @package_json end |
Class Method Details
.build ⇒ Object
45 46 47 |
# File 'lib/react_on_rails/version_checker.rb', line 45 def self.build new(package_json_path) end |
.package_json_path ⇒ Object
49 50 51 |
# File 'lib/react_on_rails/version_checker.rb', line 49 def self.package_json_path Rails.root.join("client", "package.json") end |
Instance Method Details
#major ⇒ Object
73 74 75 76 |
# File 'lib/react_on_rails/version_checker.rb', line 73 def major return if normalized.nil? normalized.match(/(\d+)\./)[1] end |
#normalized ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/react_on_rails/version_checker.rb', line 61 def normalized match = raw .tr("-", ".") .strip .match(/(\d.*)/) match.present? ? match[0] : nil end |
#raw ⇒ Object
57 58 59 |
# File 'lib/react_on_rails/version_checker.rb', line 57 def raw JSON.parse(package_json_contents)["dependencies"]["react-on-rails"] end |
#relative_path? ⇒ Boolean
69 70 71 |
# File 'lib/react_on_rails/version_checker.rb', line 69 def relative_path? normalized.nil? # must be a relative path if nil and we haven't failed end |