Class: ReactOnRails::VersionChecker::NodePackageVersion

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_jsonObject (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

.buildObject



45
46
47
# File 'lib/react_on_rails/version_checker.rb', line 45

def self.build
  new(package_json_path)
end

.package_json_pathObject



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

#majorObject



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

#normalizedObject



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

#rawObject



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

Returns:

  • (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