Class: BetweenMeals::Changes::Cookbook
- Defined in:
- lib/between_meals/changes/cookbook.rb
Overview
Changeset aware cookbook
Instance Attribute Summary
Attributes inherited from Change
Class Method Summary collapse
- .explode_path(path, cookbook_dirs) ⇒ Object
-
.find(list, cookbook_dirs, logger) ⇒ Object
Given a list of changed files create a list of Cookbook objects.
- .meaningful_cookbook_file?(path, cookbook_dirs) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(files, cookbook_dirs) ⇒ Cookbook
constructor
A new instance of Cookbook.
Methods inherited from Change
#debug, debug, #info, info, #logger=, #to_s
Constructor Details
#initialize(files, cookbook_dirs) ⇒ Cookbook
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/between_meals/changes/cookbook.rb', line 46 def initialize(files, cookbook_dirs) @files = files @name = self.class.explode_path( files.sample[:path], cookbook_dirs )[:name] # if metadata.rb is being deleted # cookbook is marked for deletion # otherwise it was modified # and will be re-uploaded if files. select { |x| x[:status] == :deleted }. map { |x| x[:path].match(%{.*metadata\.rb$}) }. compact. any? @status = :deleted else @status = :modified end end |
Class Method Details
.explode_path(path, cookbook_dirs) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/between_meals/changes/cookbook.rb', line 32 def self.explode_path(path, cookbook_dirs) cookbook_dirs.each do |dir| re = %r{^#{dir}/([^/]+)/.*} debug("[cookbook] Matching #{path} against ^#{re}") m = path.match(re) next unless m info("Cookbook is #{m[1]}") return { :cookbook_dir => dir, :name => m[1] } end nil end |
.find(list, cookbook_dirs, logger) ⇒ Object
Given a list of changed files create a list of Cookbook objects
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/between_meals/changes/cookbook.rb', line 69 def self.find(list, cookbook_dirs, logger) @@logger = logger return [] if list.nil? || list.empty? # rubocop:disable MultilineBlockChain list. group_by do |x| # Group by prefix of cookbok_dir + cookbook_name # so that we treat deletes and modifications across # two locations separately g = self.explode_path(x[:path], cookbook_dirs) g[:cookbook_dir] + '/' + g[:name] if g end. map do |_, change| # Confirm we're dealing with a cookbook # Changes to OWNERS or other stuff that might end up # in [core, other, secure] dirs are ignored is_cookbook = change.select do |c| self.meaningful_cookbook_file?(c[:path], cookbook_dirs) end.any? if is_cookbook BetweenMeals::Changes::Cookbook.new(change, cookbook_dirs) end end.compact # rubocop:enable MultilineBlockChain end |
.meaningful_cookbook_file?(path, cookbook_dirs) ⇒ Boolean
22 23 24 25 26 27 28 29 30 |
# File 'lib/between_meals/changes/cookbook.rb', line 22 def self.meaningful_cookbook_file?(path, cookbook_dirs) cookbook_dirs.each do |dir| re = %r{^#{dir}/([^/]+)/.*} m = path.match(re) debug("[cookbook] #{path} meaningful? [#{re}]: #{m}") return true if m end false end |