Sha256: 786005bbd87d42e50e7e8bb95791458c1d84d09bb48da568ec830ed57b8404a0

Contents?: true

Size: 1.3 KB

Versions: 149

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "pathname"

module Dependabot
  class DependencyFile
    attr_accessor :name, :content, :directory, :type, :support_file

    def initialize(name:, content:, directory: "/", type: "file",
                   support_file: false)
      @name = name
      @content = content
      @directory = clean_directory(directory)
      @support_file = support_file

      # Type is used *very* sparingly. It lets the git_modules updater know that
      # a "file" is actually a submodule, and lets our Go updaters know which
      # file represents the main.go.
      # New use cases should be avoided if at all possible (and use the
      # support_file flag instead)
      @type = type
    end

    def to_h
      {
        "name" => name,
        "content" => content,
        "directory" => directory,
        "type" => type
      }
    end

    def path
      Pathname.new(File.join(directory, name)).cleanpath.to_path
    end

    def ==(other)
      other.instance_of?(self.class) && to_h == other.to_h
    end

    def hash
      to_h.hash
    end

    def eql?(other)
      self.==(other)
    end

    def support_file?
      @support_file
    end

    private

    def clean_directory(directory)
      # Directory should always start with a `/`
      directory.sub(%r{^/*}, "/")
    end
  end
end

Version data entries

149 entries across 149 versions & 2 rubygems

Version Path
dependabot-common-0.98.0 lib/dependabot/dependency_file.rb
dependabot-common-0.97.11 lib/dependabot/dependency_file.rb
dependabot-common-0.97.10 lib/dependabot/dependency_file.rb
dependabot-common-0.97.9 lib/dependabot/dependency_file.rb
dependabot-common-0.97.8 lib/dependabot/dependency_file.rb
dependabot-common-0.97.7 lib/dependabot/dependency_file.rb
dependabot-common-0.97.6 lib/dependabot/dependency_file.rb
dependabot-common-0.97.5 lib/dependabot/dependency_file.rb
dependabot-common-0.97.4 lib/dependabot/dependency_file.rb
dependabot-common-0.97.3 lib/dependabot/dependency_file.rb
dependabot-common-0.97.2 lib/dependabot/dependency_file.rb
dependabot-common-0.97.1 lib/dependabot/dependency_file.rb
dependabot-common-0.97.0 lib/dependabot/dependency_file.rb
dependabot-common-0.96.1 lib/dependabot/dependency_file.rb
dependabot-common-0.96.0 lib/dependabot/dependency_file.rb
dependabot-common-0.95.85 lib/dependabot/dependency_file.rb
dependabot-common-0.95.84 lib/dependabot/dependency_file.rb
dependabot-common-0.95.83 lib/dependabot/dependency_file.rb
dependabot-common-0.95.82 lib/dependabot/dependency_file.rb
dependabot-common-0.95.81 lib/dependabot/dependency_file.rb