Module: RedmineWithGit::Patches::RedmineGitHosting::GitoliteHookPatch::InstanceMethods
- Defined in:
- lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb
Constant Summary collapse
- SHEBANG_PATTERNS =
[:ruby].map { |k| [k, /^\#!.+\s+#{::Regexp.quote(k)}\s*$/] } .to_h
Instance Method Summary collapse
- #hook_file_has_changed? ⇒ Boolean
- #install_hook_file ⇒ Object
- #on_content_replaced ⇒ Object
- #replace_shebang? ⇒ Boolean
- #ruby_shebang ⇒ String
- #shebang_from ⇒ Regexp
- #shebang_replacement ⇒ Symbol?
- #shebang_to ⇒ String
- #source_content_with_shebang_replaced ⇒ String
- #source_path ⇒ String
- #source_shebang ⇒ String
Instance Method Details
#hook_file_has_changed? ⇒ Boolean
20 21 22 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 20 def hook_file_has_changed? on_content_replaced { super } end |
#install_hook_file ⇒ Object
24 25 26 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 24 def install_hook_file on_content_replaced { super } end |
#on_content_replaced ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 28 def on_content_replaced return yield unless replace_shebang? ::EacRubyUtils::Fs::Temp.on_file do |temp_path| temp_path.write(source_content_with_shebang_replaced) @temp_source_path = temp_path.to_path yield ensure @temp_source_path = nil end end |
#replace_shebang? ⇒ Boolean
41 42 43 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 41 def replace_shebang? shebang_replacement.present? end |
#ruby_shebang ⇒ String
46 47 48 49 50 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 46 def ruby_shebang bin = ::RbConfig::CONFIG['RUBY_INSTALL_NAME'] || ::RbConfig::CONFIG['ruby_install_name'] bin += (::RbConfig::CONFIG['EXEEXT'] || ::RbConfig::CONFIG['exeext'] || '') ::File.join(::RbConfig::CONFIG['bindir'], bin) end |
#shebang_from ⇒ Regexp
53 54 55 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 53 def shebang_from SHEBANG_PATTERNS.fetch(shebang_replacement) end |
#shebang_replacement ⇒ Symbol?
58 59 60 61 62 63 64 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 58 def shebang_replacement SHEBANG_PATTERNS.each do |k, v| return k if v.match?(source_shebang) end nil end |
#shebang_to ⇒ String
67 68 69 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 67 def shebang_to "\#\!#{send("#{shebang_replacement}_shebang")}\n" end |
#source_content_with_shebang_replaced ⇒ String
82 83 84 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 82 def source_content_with_shebang_replaced ::File.read(source_path).gsub(shebang_from, shebang_to) end |
#source_path ⇒ String
72 73 74 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 72 def source_path @temp_source_path || super end |
#source_shebang ⇒ String
77 78 79 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 77 def source_shebang ::File.open(source_path, &:readline).strip end |