Class: Ridley::Chef::Chefignore

Inherits:
Object
  • Object
show all
Defined in:
lib/ridley/chef/chefignore.rb

Overview

Borrowed and modified from: https://raw.github.com/opscode/chef/62f9b0e3be8e22eef092163c331b7d3f8d350f94/lib/chef/cookbook/chefignore.rb

Copyright

Copyright © 2011 Opscode, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constant Summary collapse

FILENAME =
"chefignore".freeze
COMMENTS_AND_WHITESPACE =
/^\s*(?:#.*)?$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ignore_file_or_repo) ⇒ Chefignore

Returns a new instance of Chefignore.



39
40
41
42
# File 'lib/ridley/chef/chefignore.rb', line 39

def initialize(ignore_file_or_repo)
  @ignore_file = find_ignore_file(ignore_file_or_repo)
  @ignores     = parse_ignore_file
end

Instance Attribute Details

#ignoresObject (readonly)

Returns the value of attribute ignores.



37
38
39
# File 'lib/ridley/chef/chefignore.rb', line 37

def ignores
  @ignores
end

Class Method Details

.find_relative_to(path) ⇒ String?

Traverse a path in relative context to find a Chefignore file

Parameters:

  • path (String)

    path to traverse

Returns:

  • (String, nil)


26
27
28
29
30
31
# File 'lib/ridley/chef/chefignore.rb', line 26

def find_relative_to(path)
  [
    File.join(path, FILENAME),
    File.join(path, 'cookbooks', FILENAME)
  ].find { |f| File.exists?(f) }
end

Instance Method Details

#ignored?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/ridley/chef/chefignore.rb', line 50

def ignored?(file_name)
  @ignores.any? { |glob| File.fnmatch?(glob, file_name) }
end

#remove_ignores_from(file_list) ⇒ Object



44
45
46
47
48
# File 'lib/ridley/chef/chefignore.rb', line 44

def remove_ignores_from(file_list)
  Array(file_list).inject([]) do |unignored, file|
    ignored?(file) ? unignored : unignored << file
  end
end