Class: MaxFileSizeHook
- Inherits:
-
RubyGitHooks::Hook
- Object
- RubyGitHooks::Hook
- MaxFileSizeHook
- Defined in:
- lib/ruby_git_hooks/max_file_size.rb
Overview
This hook checks the size of each individual file against a configurable maximum size. Once a huge file is in your git history it can’t be fully removed without rewriting history, so you’re usually better off preventing them in the first place.
Constant Summary collapse
- DEFAULT_MAX_FILE_SIZE =
10*1024*1024
- VERBOSE =
false
Constants inherited from RubyGitHooks::Hook
RubyGitHooks::Hook::HOOK_INFO, RubyGitHooks::Hook::HOOK_TYPE_SETUP
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(max_size = DEFAULT_MAX_FILE_SIZE) ⇒ MaxFileSizeHook
constructor
A new instance of MaxFileSizeHook.
Methods inherited from RubyGitHooks::Hook
get_hooks_to_run, initial_setup, register, run, run_as_specific_githook, #setup, shell!
Constructor Details
#initialize(max_size = DEFAULT_MAX_FILE_SIZE) ⇒ MaxFileSizeHook
Returns a new instance of MaxFileSizeHook.
14 15 16 |
# File 'lib/ruby_git_hooks/max_file_size.rb', line 14 def initialize(max_size = DEFAULT_MAX_FILE_SIZE) @max_file_size = max_size end |
Instance Method Details
#check ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_git_hooks/max_file_size.rb', line 18 def check STDERR.puts "Checking, max file size: #{@max_file_size}" if VERBOSE okay = true file_contents.each do |name, file| STDERR.puts "File length: #{file.length}" if VERBOSE if file.length > @max_file_size okay = false STDERR.puts "File #{name} exceeds maximum allowed size!" end end okay end |