Class: BobTheBuilder::Bob
- Inherits:
-
Object
- Object
- BobTheBuilder::Bob
- Defined in:
- lib/bob_the_builder/bob.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #build(version = nil) ⇒ Object
- #changes_since_last_version? ⇒ Boolean
- #deploy(location = 'server') ⇒ Object
-
#initialize(env, repo_location = '.', branch_name = 'master') ⇒ Bob
constructor
A new instance of Bob.
- #version_bump!(change_type) ⇒ Object
Constructor Details
#initialize(env, repo_location = '.', branch_name = 'master') ⇒ Bob
Returns a new instance of Bob.
5 6 7 8 9 10 11 |
# File 'lib/bob_the_builder/bob.rb', line 5 def initialize(env, repo_location = '.', branch_name = 'master') @environment = env @repo = Git.open(repo_location) if repo.branches.any? { |br| br.name == branch_name } repo.branch(branch_name).checkout end end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
3 4 5 |
# File 'lib/bob_the_builder/bob.rb', line 3 def environment @environment end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
3 4 5 |
# File 'lib/bob_the_builder/bob.rb', line 3 def output @output end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
3 4 5 |
# File 'lib/bob_the_builder/bob.rb', line 3 def repo @repo end |
Instance Method Details
#build(version = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bob_the_builder/bob.rb', line 27 def build(version = nil) version ||= current_version ohai "Updating submodules..." git('submodule init') git('submodule update') ohai "Submodules updated" ohai "Building..." ['date'] = Time.now.strftime("%Y-%m-%d") ['version'] = version FileUtils.mkdir_p(File.dirname(File.(option('output')))) run option('build_command') @output = option('output') ohai "Done! Compiled to", output output end |
#changes_since_last_version? ⇒ Boolean
60 61 62 63 64 |
# File 'lib/bob_the_builder/bob.rb', line 60 def changes_since_last_version? newer_commits.any? do |commit| commit. =~ Regexp.new(option('changes_regexp')) end end |
#deploy(location = 'server') ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bob_the_builder/bob.rb', line 45 def deploy(location = 'server') unless output ohai("In order to deploy there must be at least one build") return end if location == 'server' upload_to_server elsif location == 'github' upload_to_github else ohai "I don't know how to deploy to", location end end |
#version_bump!(change_type) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bob_the_builder/bob.rb', line 13 def version_bump!(change_type) unless change_type == 'patch' || change_type == 'minor' || change_type == 'major' ohai "Change type not recognized selecting 'patch' as default value" change_type = 'patch' end @current_version = next_version(change_type) ohai "Updating git version" repo.add_tag(current_version) repo.push('origin', repo.branch.name, true) ohai "Git version updated to", current_version end |