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.
27 28 29 30 |
# File 'lib/wax_tasks/branch.rb', line 27 def initialize(site, target) @site = site @target = target end |
Instance Attribute Details
#baseurl ⇒ String
the site baseurl to build with (if on gh-pages)
15 16 17 |
# File 'lib/wax_tasks/branch.rb', line 15 def baseurl @baseurl end |
#commit_msg ⇒ String
the commit message to use on push
15 16 17 |
# File 'lib/wax_tasks/branch.rb', line 15 def commit_msg @commit_msg end |
#origin ⇒ String
the current repository remote
15 16 17 |
# File 'lib/wax_tasks/branch.rb', line 15 def origin @origin end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
16 17 18 |
# File 'lib/wax_tasks/branch.rb', line 16 def success @success end |
#success_msg ⇒ String
informative message to be output to console
15 16 17 |
# File 'lib/wax_tasks/branch.rb', line 15 def success_msg @success_msg end |
#target ⇒ String
the name of the Git branch to deploy to
15 16 17 |
# File 'lib/wax_tasks/branch.rb', line 15 def target @target end |
Class Method Details
.inherited ⇒ Object
This method ensures child classes can be instantiated eventhough Branch.new cannot be.
21 22 23 |
# File 'lib/wax_tasks/branch.rb', line 21 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 #{WaxTasks::SITE_DIR}" unless Dir.exist? WaxTasks::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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wax_tasks/branch.rb', line 34 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?(WaxTasks::SITE_DIR) opts = { source: @site[:source_dir] || '.', destination: WaxTasks::SITE_DIR, config: WaxTasks::DEFAULT_CONFIG, baseurl: @baseurl, verbose: true } Jekyll::Site.new(Jekyll.configuration(opts)).process end |