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 <svenfuchs@artweb-design.de>

Direct Known Subclasses

Component::VersionFile

Constant Summary

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (VersionFile) initialize(target)

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

- (Object) target (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

- (Object) bump!



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

- (Object) filename



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

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

- (Object) new_number



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

- (Object) old_number



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

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