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].index_with { |k| /^\#!.+\s+#{::Regexp.quote(k)}\s*$/ }
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
18 19 20 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 18 def hook_file_has_changed? on_content_replaced { super } end |
#install_hook_file ⇒ Object
22 23 24 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 22 def install_hook_file on_content_replaced { super } end |
#on_content_replaced ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 26 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
39 40 41 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 39 def replace_shebang? shebang_replacement.present? end |
#ruby_shebang ⇒ String
44 45 46 47 48 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 44 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
51 52 53 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 51 def shebang_from SHEBANG_PATTERNS.fetch(shebang_replacement) end |
#shebang_replacement ⇒ Symbol?
56 57 58 59 60 61 62 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 56 def shebang_replacement SHEBANG_PATTERNS.each do |k, v| return k if v.match?(source_shebang) end nil end |
#shebang_to ⇒ String
65 66 67 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 65 def shebang_to "#!#{send("#{shebang_replacement}_shebang")}\n" end |
#source_content_with_shebang_replaced ⇒ String
80 81 82 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 80 def source_content_with_shebang_replaced ::File.read(source_path).gsub(shebang_from, shebang_to) end |
#source_path ⇒ String
70 71 72 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 70 def source_path @temp_source_path || super end |
#source_shebang ⇒ String
75 76 77 |
# File 'lib/redmine_with_git/patches/redmine_git_hosting/gitolite_hook_patch.rb', line 75 def source_shebang ::File.open(source_path, &:readline).strip end |