Class: Berkshelf::Chef::Cookbook::Chefignore
- Inherits:
-
Object
- Object
- Berkshelf::Chef::Cookbook::Chefignore
- Defined in:
- lib/berkshelf/chef/cookbook/chefignore.rb
Overview
Borrowed and modified from: https://raw.github.com/opscode/chef/11.4.0/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
-
#ignores ⇒ Object
readonly
Returns the value of attribute ignores.
Class Method Summary collapse
-
.find_relative_to(path) ⇒ String?
Traverse a path in relative context to find a Chefignore file.
Instance Method Summary collapse
- #ignored?(file_name) ⇒ Boolean
-
#initialize(ignore_file_or_repo) ⇒ Chefignore
constructor
A new instance of Chefignore.
- #remove_ignores_from(file_list) ⇒ Object
Constructor Details
#initialize(ignore_file_or_repo) ⇒ Chefignore
Returns a new instance of Chefignore.
38 39 40 41 |
# File 'lib/berkshelf/chef/cookbook/chefignore.rb', line 38 def initialize(ignore_file_or_repo) @ignore_file = find_ignore_file(ignore_file_or_repo) @ignores = parse_ignore_file end |
Instance Attribute Details
#ignores ⇒ Object (readonly)
Returns the value of attribute ignores.
36 37 38 |
# File 'lib/berkshelf/chef/cookbook/chefignore.rb', line 36 def ignores @ignores end |
Class Method Details
.find_relative_to(path) ⇒ String?
Traverse a path in relative context to find a Chefignore file
25 26 27 28 29 30 |
# File 'lib/berkshelf/chef/cookbook/chefignore.rb', line 25 def find_relative_to(path) [ File.join(path, Berkshelf::Chef::Cookbook::Chefignore::FILENAME), File.join(path, 'cookbooks', Berkshelf::Chef::Cookbook::Chefignore::FILENAME) ].find { |f| File.exists?(f) } end |
Instance Method Details
#ignored?(file_name) ⇒ Boolean
49 50 51 |
# File 'lib/berkshelf/chef/cookbook/chefignore.rb', line 49 def ignored?(file_name) @ignores.any? {|glob| File.fnmatch?(glob, file_name)} end |
#remove_ignores_from(file_list) ⇒ Object
43 44 45 46 47 |
# File 'lib/berkshelf/chef/cookbook/chefignore.rb', line 43 def remove_ignores_from(file_list) Array(file_list).inject([]) do |unignored, file| ignored?(file) ? unignored : unignored << file end end |