Class: WaxTasks::Branch
- Inherits:
-
Object
- Object
- WaxTasks::Branch
- Defined in:
- lib/wax_tasks/branch.rb
Overview
Parent class representing a Git Branch that cannot be created directly. Only child classes (LocalBranch, TravisBranch) can be initialized.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#baseurl ⇒ String
the site baseurl to build with (if on gh-pages).
-
#commit_msg ⇒ String
the commit message to use on push.
-
#origin ⇒ String
the current repository remote.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
-
#success_msg ⇒ String
informative message to be output to console.
-
#target ⇒ String
the name of the Git branch to deploy to.
Class Method Summary collapse
-
.inherited ⇒ Object
This method ensures child classes can be instantiated eventhough Branch.new cannot be.
Instance Method Summary collapse
-
#initialize(site, target) ⇒ Branch
constructor
A new instance of Branch.
-
#push ⇒ Nil
Add, commmit, and push compiled Jekyll site to @target branch.
-
#rebuild ⇒ Nil
Rebuild the Jekyll site with branch @baseurl.
Constructor Details
#initialize(site, target) ⇒ Branch
Returns a new instance of Branch.
28 29 30 31 |
# File 'lib/wax_tasks/branch.rb', line 28 def initialize(site, target) @site = site @target = target end |
Instance Attribute Details
#baseurl ⇒ String
the site baseurl to build with (if on gh-pages)
16 17 18 |
# File 'lib/wax_tasks/branch.rb', line 16 def baseurl @baseurl end |
#commit_msg ⇒ String
the commit message to use on push
16 17 18 |
# File 'lib/wax_tasks/branch.rb', line 16 def commit_msg @commit_msg end |
#origin ⇒ String
the current repository remote
16 17 18 |
# File 'lib/wax_tasks/branch.rb', line 16 def origin @origin end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
17 18 19 |
# File 'lib/wax_tasks/branch.rb', line 17 def success @success end |
#success_msg ⇒ String
informative message to be output to console
16 17 18 |
# File 'lib/wax_tasks/branch.rb', line 16 def success_msg @success_msg end |
#target ⇒ String
the name of the Git branch to deploy to
16 17 18 |
# File 'lib/wax_tasks/branch.rb', line 16 def target @target end |
Class Method Details
.inherited ⇒ Object
This method ensures child classes can be instantiated eventhough Branch.new cannot be.
22 23 24 |
# File 'lib/wax_tasks/branch.rb', line 22 def self.inherited(*) public_class_method :new end |
Instance Method Details
#push ⇒ Nil
Add, commmit, and push compiled Jekyll site to @target branch
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/wax_tasks/branch.rb', line 52 def push if @site[:env] == 'prod' rebuild if @target == 'gh-pages' raise Error::MissingSite, "Cannot find #{SITE_DIR}" unless Dir.exist? SITE_DIR Dir.chdir(SITE_DIR) system 'git init && git add .' system "git commit -m '#{@commit_msg}'" system "git remote add origin #{@origin}" puts @success_msg.cyan system "git push origin master:refs/heads/#{@target} --force" else puts "Skipping build for branch '#{@target}' on env='test'".orange end end |
#rebuild ⇒ Nil
Rebuild the Jekyll site with branch @baseurl
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wax_tasks/branch.rb', line 35 def rebuild if @baseurl.empty? msg = 'Building the gh-pages _site without a baseurl is not recommended' Logger.new($stdout).warn(msg.orange) end FileUtils.rm_r(SITE_DIR) if File.directory?(SITE_DIR) opts = { source: '.', destination: SITE_DIR, baseurl: @baseurl, verbose: true } Jekyll::Site.new(Jekyll.configuration(opts)).process end |