Class: Tumbler::Manager::Version
- Inherits:
-
Object
- Object
- Tumbler::Manager::Version
- Defined in:
- lib/tumbler/manager/version.rb
Constant Summary collapse
- DEFAULT_FIELD =
[:major, :minor, :tiny]
- INITIAL_VERSION =
'0.0.0'
Constants included from Informer
Instance Attribute Summary collapse
-
#basefile ⇒ Object
readonly
Returns the value of attribute basefile.
-
#field_names ⇒ Object
readonly
Returns the value of attribute field_names.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Attributes included from Runner
Instance Method Summary collapse
- #base ⇒ Object
- #bump(level) ⇒ Object
- #commit(from) ⇒ Object
- #extract ⇒ Object
- #fields(f) ⇒ Object
- #filename(file) ⇒ Object
- #generate_with_new(version) ⇒ Object
-
#initialize(manager, &block) ⇒ Version
constructor
A new instance of Version.
- #reload ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Methods included from Informer
Methods included from Runner
Constructor Details
#initialize(manager, &block) ⇒ Version
Returns a new instance of Version.
12 13 14 15 16 17 |
# File 'lib/tumbler/manager/version.rb', line 12 def initialize(manager, &block) @manager = manager filename(manager.default_version_file) fields(DEFAULT_FIELD) instance_eval(&block) if block end |
Instance Attribute Details
#basefile ⇒ Object (readonly)
Returns the value of attribute basefile.
7 8 9 |
# File 'lib/tumbler/manager/version.rb', line 7 def basefile @basefile end |
#field_names ⇒ Object (readonly)
Returns the value of attribute field_names.
7 8 9 |
# File 'lib/tumbler/manager/version.rb', line 7 def field_names @field_names end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/tumbler/manager/version.rb', line 7 def file @file end |
Instance Method Details
#base ⇒ Object
66 67 68 |
# File 'lib/tumbler/manager/version.rb', line 66 def base @manager.base end |
#bump(level) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tumbler/manager/version.rb', line 48 def bump(level) inform "Bumping version to #{@version.bump(level).to_s}" do if @manager.noop @manager.dry "Bumping version to #{@version.bump(level).to_s}" else new_file = generate_with_new(@version.bump(level).to_s) File.open(file, 'w') {|f| f << new_file } reload end end end |
#commit(from) ⇒ Object
60 61 62 63 64 |
# File 'lib/tumbler/manager/version.rb', line 60 def commit(from) inform "Committing version `#{@basefile}'" do sh "git commit #{@basefile} -m'Bumped version from #{from} to #{to_s}'" end end |
#extract ⇒ Object
27 28 29 |
# File 'lib/tumbler/manager/version.rb', line 27 def extract File.read(@file)[/Version\s*=\s*['"](.*?)['"]/i, 1] end |
#fields(f) ⇒ Object
19 20 21 |
# File 'lib/tumbler/manager/version.rb', line 19 def fields(f) @field_names = (f == :all ? @version.field_names : f) end |
#filename(file) ⇒ Object
35 36 37 38 |
# File 'lib/tumbler/manager/version.rb', line 35 def filename(file) @basefile = file @file = File.join(@manager.base, file) end |
#generate_with_new(version) ⇒ Object
31 32 33 |
# File 'lib/tumbler/manager/version.rb', line 31 def generate_with_new(version) File.read(@file).gsub(/(Version\s*=\s*['"])(.*?)(['"])/i, "\\1#{version.to_s}\\3") end |
#reload ⇒ Object
23 24 25 |
# File 'lib/tumbler/manager/version.rb', line 23 def reload @version = Versionomy.parse(File.exist?(file) ? extract : '0.0.0') end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/tumbler/manager/version.rb', line 44 def to_s value.to_s end |
#value ⇒ Object
40 41 42 |
# File 'lib/tumbler/manager/version.rb', line 40 def value @version end |