Sha256: c26d613ed6a1af627ebc4ab55fd2366df9814fe9416f6c983b72df28866a4e9b

Contents?: true

Size: 1.01 KB

Versions: 98

Compression:

Stored size: 1.01 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)
      @type = type
      @support_file = support_file
    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

98 entries across 98 versions & 1 rubygems

Version Path
dependabot-core-0.90.7 lib/dependabot/dependency_file.rb
dependabot-core-0.90.6 lib/dependabot/dependency_file.rb
dependabot-core-0.90.5 lib/dependabot/dependency_file.rb
dependabot-core-0.90.4 lib/dependabot/dependency_file.rb
dependabot-core-0.90.3 lib/dependabot/dependency_file.rb
dependabot-core-0.90.2 lib/dependabot/dependency_file.rb
dependabot-core-0.90.1 lib/dependabot/dependency_file.rb
dependabot-core-0.90.0 lib/dependabot/dependency_file.rb
dependabot-core-0.89.5 lib/dependabot/dependency_file.rb
dependabot-core-0.89.4 lib/dependabot/dependency_file.rb
dependabot-core-0.89.3 lib/dependabot/dependency_file.rb
dependabot-core-0.89.2 lib/dependabot/dependency_file.rb
dependabot-core-0.89.1 lib/dependabot/dependency_file.rb
dependabot-core-0.89.0 lib/dependabot/dependency_file.rb
dependabot-core-0.88.3 lib/dependabot/dependency_file.rb
dependabot-core-0.88.2 lib/dependabot/dependency_file.rb
dependabot-core-0.88.1 lib/dependabot/dependency_file.rb
dependabot-core-0.88.0 lib/dependabot/dependency_file.rb
dependabot-core-0.87.15 lib/dependabot/dependency_file.rb
dependabot-core-0.87.14 lib/dependabot/dependency_file.rb