Class: FeduxOrgStdlib::VersionManagement::RubygemVersionFileParser

Inherits:
Object
  • Object
show all
Defined in:
lib/fedux_org_stdlib/version_management/rubygem_version_file_parser.rb

Overview

Ruby version file parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modulesObject (readonly)

Returns the value of attribute modules.



10
11
12
# File 'lib/fedux_org_stdlib/version_management/rubygem_version_file_parser.rb', line 10

def modules
  @modules
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/fedux_org_stdlib/version_management/rubygem_version_file_parser.rb', line 10

def version
  @version
end

Instance Method Details

#parse(file) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/fedux_org_stdlib/version_management/rubygem_version_file_parser.rb', line 12

def parse(file)
  data = File.read(file)

  @version = data.match(/(?:VERSION|Version)\s+=\s+["']([^'"]+)["']/) { Regexp.last_match[1] }
  @modules = data.scan(/^\s*module\s+([A-Z][A-Za-z0-9]+(?:::[A-Z][A-Z0-9a-z]+)*)$/x).flatten

  fail Exceptions::VersionFileInvalid, JSON.dump(file: file) if version.blank?
end