Module: Semmy::VersionFile

Extended by:
VersionFile
Included in:
VersionFile
Defined in:
lib/semmy/version_file.rb

Defined Under Namespace

Classes: ConstantNotFound, NotFound, Update, UpdateFailed

Instance Method Summary collapse

Instance Method Details

#find(gem_name) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/semmy/version_file.rb', line 11

def find(gem_name)
  gem_name_matcher = gem_name.gsub(/[_-]/, '[/_-]')

  Dir.glob('lib/**/version.rb').detect do |file_name|
    file_name =~ %r{lib/#{gem_name_matcher}/version.rb}
  end || fail(NotFound, 'No version file found.')
end

#parse_version(contents) ⇒ Object



19
20
21
22
23
24
# File 'lib/semmy/version_file.rb', line 19

def parse_version(contents)
  match = contents.match(/VERSION\s*=\s*['"]([^'"]+)['"]/) ||
    fail(ConstantNotFound, 'Could not find version constant')

  match[1]
end