Class: GitHooks::Repository::Limiter

Inherits:
Object
  • Object
show all
Defined in:
lib/githooks/repository/limiter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, options = {}) ⇒ Limiter

Returns a new instance of Limiter.



24
25
26
27
28
# File 'lib/githooks/repository/limiter.rb', line 24

def initialize(type, options = {})
  @type     = type
  @only     = options.delete(:only) || options.delete(:to)
  @inverted = false
end

Instance Attribute Details

#only(*args) ⇒ Object (readonly) Also known as: to

Returns the value of attribute only.



22
23
24
# File 'lib/githooks/repository/limiter.rb', line 22

def only
  @only
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/githooks/repository/limiter.rb', line 22

def type
  @type
end

Instance Method Details

#invertedObject Also known as: invert



37
38
39
# File 'lib/githooks/repository/limiter.rb', line 37

def inverted
  @inverted = true
end

#limit(files) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/githooks/repository/limiter.rb', line 42

def limit(files)
  files.select! do |file|
    match_file(file, @only).tap do |result|
      if GitHooks.debug?
        result = (result ? 'success' : 'failure')
        STDERR.puts "  #{file.path} (#{file.attribute_value(@type).inspect}) was a #{result}"
      end
    end
  end
end