Class: R3po::App
- Inherits:
-
Object
- Object
- R3po::App
- Defined in:
- lib/r3po.rb
Instance Attribute Summary collapse
-
#version_path ⇒ Object
Returns the value of attribute version_path.
Class Method Summary collapse
Instance Method Summary collapse
- #add(file, &block) ⇒ Object
- #checkout_branch(branch, &block) ⇒ Object
- #commit(message, &block) ⇒ Object
- #create_tag(tag, &block) ⇒ Object
- #current_branch(&block) ⇒ Object
- #delete_branch(branch, &block) ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #merge(source, target, &block) ⇒ Object
- #new_branch(source, branch, &block) ⇒ Object
- #print_error(message) ⇒ Object
-
#print_success(operation, message) ⇒ Object
Pretty print methods.
- #push(branch, &block) ⇒ Object
-
#run(command, message, &block) ⇒ Object
Command methods.
- #version {|version| ... } ⇒ Object
- #version=(value) ⇒ Object
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
14 15 16 |
# File 'lib/r3po.rb', line 14 def initialize @version_path = 'version' end |
Instance Attribute Details
#version_path ⇒ Object
Returns the value of attribute version_path.
12 13 14 |
# File 'lib/r3po.rb', line 12 def version_path @version_path end |
Class Method Details
.instance ⇒ Object
18 19 20 |
# File 'lib/r3po.rb', line 18 def self.instance return (@@instance ||= new) end |
Instance Method Details
#add(file, &block) ⇒ Object
127 128 129 |
# File 'lib/r3po.rb', line 127 def add( file, &block ) run( "add #{file}", "Couldn't add file #{file}.", &block ) end |
#checkout_branch(branch, &block) ⇒ Object
78 79 80 |
# File 'lib/r3po.rb', line 78 def checkout_branch( branch, &block ) run( "checkout #{branch}", "Could not check out #{branch}.", &block ) end |
#commit(message, &block) ⇒ Object
131 132 133 |
# File 'lib/r3po.rb', line 131 def commit( , &block ) run( "commit -m \"#{}\"", "Could not commit changes.", &block ) end |
#create_tag(tag, &block) ⇒ Object
121 122 123 124 125 |
# File 'lib/r3po.rb', line 121 def create_tag( tag, &block ) checkout_branch( MASTER ) do run( "tag #{tag}", "Could not create tag #{tag}.", &block ) end end |
#current_branch(&block) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/r3po.rb', line 90 def current_branch( &block ) run( "rev-parse --abbrev-ref HEAD", "Could not divine the current branch name." ) do |branch| case branch when /^#{FEATURE}\/(.*)$/ branch = [FEATURE, $1] when /^#{RELEASE}\/(.*)$/ branch = [RELEASE, $1] when /^#{PATCH}\/(.*)$/ branch = [PATCH, $1] end unless branch.kind_of?( Array ) print_error( "Unknown branch format (#{branch})." ) else yield branch if block_given? return branch end end end |
#delete_branch(branch, &block) ⇒ Object
72 73 74 75 76 |
# File 'lib/r3po.rb', line 72 def delete_branch( branch, &block ) run( "branch -D #{branch}", "Could not delete local branch #{branch}." ) do push( ":#{branch}", &block ) end end |
#merge(source, target, &block) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/r3po.rb', line 110 def merge( source, target, &block ) checkout_branch( target ) do run( "merge --no-ff -m 'Merging #{source} into #{target}' #{source}", "Could not merge #{source} into #{target}. Try to manually merge to see if there are conflicts." ) do push( target, &block ) end end end |
#new_branch(source, branch, &block) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/r3po.rb', line 82 def new_branch( source, branch, &block ) checkout_branch( source ) do run( "checkout -b #{branch}", "Could not start a new branch #{branch}." ) do push( branch, &block ) end end end |
#print_error(message) ⇒ Object
141 142 143 |
# File 'lib/r3po.rb', line 141 def print_error( ) puts 'ERROR: '.red + end |
#print_success(operation, message) ⇒ Object
Pretty print methods
137 138 139 |
# File 'lib/r3po.rb', line 137 def print_success( operation, ) puts "#{operation}: ".green + end |
#push(branch, &block) ⇒ Object
68 69 70 |
# File 'lib/r3po.rb', line 68 def push( branch, &block ) run( "push origin #{branch}", "Could not push up the branch #{branch}.", &block ) end |
#run(command, message, &block) ⇒ Object
Command methods
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/r3po.rb', line 57 def run( command, , &block ) result = `git #{command} 2>&1` unless $?.success? print_error( "#{}\n#{result}" ) return false else yield result if block_given? return true end end |
#version {|version| ... } ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/r3po.rb', line 22 def version( &block ) if File.exists?( @version_path ) version = File.read( @version_path ) unless version =~ /^(\d+)\.(\d+)\.(\d+)/ print_error( "The version file contained a poorly formed version number." ) return end version = $1.to_i, $2.to_i, $3.to_i else puts %Q{ #{"Warning:".yellow} Writing out a default version file as I couldn't find one. Please make sure your code uses this file to detect its version as I will update it so that we maintain a clean R3po. Follow semantic versioning, as described here: http://guides.rubygems.org/patterns/#semantic-versioning } self.version = '0.0.0' version = 0, 0, 0 end yield *version if block_given? return version end |
#version=(value) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/r3po.rb', line 48 def version=( value ) File.write( @version_path, value ) add( @version_path ) do commit( "Updating application version to #{value}." ) end end |