Class: Gantree::Wiki
- Inherits:
-
Object
- Object
- Gantree::Wiki
- Defined in:
- lib/gantree/wiki.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#wiki_path ⇒ Object
readonly
Returns the value of attribute wiki_path.
Instance Method Summary collapse
- #add_to_top ⇒ Object
- #execute(cmd) ⇒ Object
-
#initialize(notes, filename, wiki_url, path = '/tmp/') ⇒ Wiki
constructor
A new instance of Wiki.
- #pull ⇒ Object
- #push ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(notes, filename, wiki_url, path = '/tmp/') ⇒ Wiki
Returns a new instance of Wiki.
5 6 7 8 9 10 11 |
# File 'lib/gantree/wiki.rb', line 5 def initialize(notes, filename, wiki_url, path='/tmp/') @notes = notes @wiki_url = wiki_url wiki_path = wiki_url.split("/").last.sub(".git","") @wiki_path = "#{path}#{wiki_path}" @file_path = "#{@wiki_path}/#{filename}" end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/gantree/wiki.rb', line 4 def file_path @file_path end |
#wiki_path ⇒ Object (readonly)
Returns the value of attribute wiki_path.
3 4 5 |
# File 'lib/gantree/wiki.rb', line 3 def wiki_path @wiki_path end |
Instance Method Details
#add_to_top ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/gantree/wiki.rb', line 34 def add_to_top data = IO.read(@file_path) if File.exist?(@file_path) File.open(@file_path, "w") do |file| file.write(@notes) file.write("\n") file.write(data) if data end true end |
#execute(cmd) ⇒ Object
53 54 55 |
# File 'lib/gantree/wiki.rb', line 53 def execute(cmd) `#{cmd}` end |
#pull ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gantree/wiki.rb', line 19 def pull puts "Updating wiki cached repo".colorize(:yellow) if File.exist?(@wiki_path) Dir.chdir(@wiki_path) do execute("git checkout master") unless execute("git branch").include?("* master") execute("git pull origin master") end else dirname = File.dirname(@wiki_path) FileUtils.mkdir_p(dirname) unless File.exist?(dirname) cmd = "cd #{dirname} && git clone #{@wiki_url}" execute(cmd) end end |
#push ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/gantree/wiki.rb', line 44 def push Dir.chdir(@wiki_path) do basename = File.basename(@file_path) execute("git add #{basename}") execute(%Q|git commit -m "Update release notes"|) execute("git push origin master") end end |
#update ⇒ Object
13 14 15 16 17 |
# File 'lib/gantree/wiki.rb', line 13 def update pull added = add_to_top push if added end |