Class: SocialStream::Release::Global::VersionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/social_stream/release/global/version_file.rb

Overview

Manage component’s version files

This code is based on gem_release’s version_file.rb github.com/svenfuchs/gem-release

Copyright © 2010 Sven Fuchs <[email protected]>

Direct Known Subclasses

Component::VersionFile

Constant Summary collapse

VERSION_PATTERN =
/(VERSION\s*=\s*(?:"|'))(\d+\.\d+\.\d+)("|')/
NUMBER_PATTERN =
/(\d+)\.(\d+)\.(\d+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ VersionFile

Returns a new instance of VersionFile.



16
17
18
# File 'lib/social_stream/release/global/version_file.rb', line 16

def initialize(target)
  @target = target || :patch
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



14
15
16
# File 'lib/social_stream/release/global/version_file.rb', line 14

def target
  @target
end

Instance Method Details

#bump!Object



20
21
22
23
24
25
26
27
# File 'lib/social_stream/release/global/version_file.rb', line 20

def bump!
  # Must load content before writing to it
  content

  File.open(filename, 'w+') { |f| f.write(bumped_content) }

  new_number
end

#filenameObject



39
40
41
# File 'lib/social_stream/release/global/version_file.rb', line 39

def filename
  "lib/social_stream/version.rb"
end

#new_numberObject



29
30
31
32
33
# File 'lib/social_stream/release/global/version_file.rb', line 29

def new_number
  @new_number ||= old_number.sub(NUMBER_PATTERN) do
    respond_to?(target, true) ? send(target, $1, $2, $3) : target
  end
end

#old_numberObject



35
36
37
# File 'lib/social_stream/release/global/version_file.rb', line 35

def old_number
  @old_number ||= content =~ VERSION_PATTERN && $2
end