Module: Dahistory::Base
- Included in:
- Dahistory
- Defined in:
- lib/Dahistory.rb
Instance Method Summary collapse
- #backup_file(str = :RETURN) ⇒ Object
- #dirs(*args) ⇒ Object
- #file(path) ⇒ Object
- #git_add_commit ⇒ Object
- #git_add_commit_push(args = "") ⇒ Object
- #initialize(file_path = nil) {|_self| ... } ⇒ Object
- #on_raise_pending(&blok) ⇒ Object
- #pending_dir(dir) ⇒ Object
- #save ⇒ Object
Instance Method Details
#backup_file(str = :RETURN) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/Dahistory.rb', line 80 def backup_file str = :RETURN if str == :RETURN @backup_file ||= "#{`hostname`.strip}-#{file.gsub('/',',')}.#{Time.now.utc.strftime "%Y.%m.%d.%H.%M.%S"}" return File.join( pending_dir, @backup_file ) end @backup_file = str end |
#dirs(*args) ⇒ Object
36 37 38 |
# File 'lib/Dahistory.rb', line 36 def dirs *args @dirs = args.flatten.map { |dir| File. dir } end |
#file(path) ⇒ Object
32 33 34 |
# File 'lib/Dahistory.rb', line 32 def file path @file = File.(path) end |
#git_add_commit ⇒ Object
89 90 91 |
# File 'lib/Dahistory.rb', line 89 def git_add_commit @git = :commit end |
#git_add_commit_push(args = "") ⇒ Object
93 94 95 |
# File 'lib/Dahistory.rb', line 93 def git_add_commit_push args = "" @git = args end |
#initialize(file_path = nil) {|_self| ... } ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/Dahistory.rb', line 20 def initialize file_path = nil @git = false @file = nil file!(file_path) if file_path dirs './history' pending_dir './pending' @on_raise_pending = nil yield(self) if block_given? end |
#on_raise_pending(&blok) ⇒ Object
44 45 46 |
# File 'lib/Dahistory.rb', line 44 def on_raise_pending &blok @on_raise_pending = blok end |
#pending_dir(dir) ⇒ Object
40 41 42 |
# File 'lib/Dahistory.rb', line 40 def pending_dir dir @pending_dir = File.(dir) end |
#save ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/Dahistory.rb', line 97 def save content = File.read(file) standard = content.gsub("\r", '') old = self.class.find_file_copy file, dirs if !old File.write(backup_file, content) unless self.class.find_file_copy(file, pending_dir) if @git Exit_Zero "git add #{backup_file}" Exit_Zero %! git commit -m "Backup: #{backup_file}"! end if @git.is_a?(String) Exit_Zero %! git push #{@git} ! end on_raise_pending.call if on_raise_pending raise Pending, backup_file end end |