Class: Rdm::Handlers::DiffPackageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rdm/handlers/diff_package_handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, revision:) ⇒ DiffPackageHandler

Returns a new instance of DiffPackageHandler.



11
12
13
14
15
16
17
# File 'lib/rdm/handlers/diff_package_handler.rb', line 11

def initialize(path:, revision:)
  @path     = path
  @revision = revision

  source_path   = Rdm::SourceLocator.locate(path)
  @all_packages = Rdm::SourceParser.read_and_init_source(source_path).packages.values
end

Instance Attribute Details

#all_packagesObject (readonly)

Returns the value of attribute all_packages.



10
11
12
# File 'lib/rdm/handlers/diff_package_handler.rb', line 10

def all_packages
  @all_packages
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/rdm/handlers/diff_package_handler.rb', line 10

def path
  @path
end

#revisionObject (readonly)

Returns the value of attribute revision.



10
11
12
# File 'lib/rdm/handlers/diff_package_handler.rb', line 10

def revision
  @revision
end

Class Method Details

.handle(path:, revision: 'HEAD') ⇒ Object



5
6
7
# File 'lib/rdm/handlers/diff_package_handler.rb', line 5

def handle(path:, revision: 'HEAD')
  return Rdm::Handlers::DiffPackageHandler.new(path: path, revision: revision).handle
end

Instance Method Details

#handleObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rdm/handlers/diff_package_handler.rb', line 19

def handle
  @revision = 'HEAD' if @revision.nil? || @revision.empty?

  modified_packages = Rdm::Git::DiffManager
    .run(path: path, revision: revision)
    .reject { |file| file.include?(Rdm::Gen::Init::LOCAL_TEMPLATES_PATH) }
    .map { |file| Rdm::Packages::Locator.locate(file) rescue nil }
    .map { |path_to_package| Rdm::PackageParser.parse_file(path_to_package).name rescue nil }
    .reject(&:blank?)
    .uniq

  return get_dependencies(modified_packages) || []
end