Class: Milkode::IgnoreSetting
- Inherits:
-
Object
- Object
- Milkode::IgnoreSetting
- Defined in:
- lib/milkode/common/ignore_setting.rb
Instance Attribute Summary collapse
-
#ignores ⇒ Object
readonly
Returns the value of attribute ignores.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #ignore?(path) ⇒ Boolean
-
#initialize(path, ignores) ⇒ IgnoreSetting
constructor
A new instance of IgnoreSetting.
Constructor Details
#initialize(path, ignores) ⇒ IgnoreSetting
Returns a new instance of IgnoreSetting.
23 24 25 26 27 28 29 30 31 |
# File 'lib/milkode/common/ignore_setting.rb', line 23 def initialize(path, ignores) @path = path @ignores = ignores.map{|v| v.sub(/\/\Z/, "")} @regexp = @ignores.map do |v| v = "(\/|\\A)" + Regexp.escape(v).gsub('\\*', "[^/]*") + "(\/|\\Z)" Regexp.new(v) end end |
Instance Attribute Details
#ignores ⇒ Object (readonly)
Returns the value of attribute ignores.
11 12 13 |
# File 'lib/milkode/common/ignore_setting.rb', line 11 def ignores @ignores end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/milkode/common/ignore_setting.rb', line 10 def path @path end |
Class Method Details
.create_from_gitignore(path, str) ⇒ Object
13 14 15 |
# File 'lib/milkode/common/ignore_setting.rb', line 13 def self.create_from_gitignore(path, str) IgnoreSetting.new(path, parse_gitignore(str)) end |
.parse_gitignore(str) ⇒ Object
17 18 19 20 21 |
# File 'lib/milkode/common/ignore_setting.rb', line 17 def self.parse_gitignore(str) ignores = str.split($/) ignores.delete_if{|v| v =~ /(\A#.*)|(\A\Z)/} ignores end |
Instance Method Details
#ignore?(path) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/milkode/common/ignore_setting.rb', line 33 def ignore?(path) return false unless path.start_with?(@path) if (path.size == @path.size) false else if (@path == '/') ignore_in?(path) else ignore_in?(path[@path.size..-1]) end end end |