Class: OpsWalrus::PackageFile

Inherits:
Object
  • Object
show all
Defined in:
lib/opswalrus/package_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_file_path) ⇒ PackageFile

Returns a new instance of PackageFile.



65
66
67
68
69
# File 'lib/opswalrus/package_file.rb', line 65

def initialize(package_file_path)
  @package_file_path = package_file_path.to_pathname.expand_path
  @yaml = YAML.load(File.read(package_file_path)) if @package_file_path.exist?
  @yaml ||= {}
end

Instance Attribute Details

#package_file_pathObject

Returns the value of attribute package_file_path.



62
63
64
# File 'lib/opswalrus/package_file.rb', line 62

def package_file_path
  @package_file_path
end

#yamlObject

Returns the value of attribute yaml.



63
64
65
# File 'lib/opswalrus/package_file.rb', line 63

def yaml
  @yaml
end

Instance Method Details

#containing_directoryObject



92
93
94
# File 'lib/opswalrus/package_file.rb', line 92

def containing_directory
  Pathname.new(@package_file_path).parent
end

#dependenciesObject

returns a map of the form: {“local_package_name” => PackageReference1, … }



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/opswalrus/package_file.rb', line 97

def dependencies
  @dependencies ||= begin
    dependencies_hash = yaml["dependencies"] || {}
    dependencies_hash.map do |local_name, package_defn|
      package_reference = case package_defn
      in String => package_url
        PackageReference.new(local_name, package_url)
      in Hash
        url = package_defn["url"]
        version = package_defn["version"]
        PackageReference.new(local_name, url, version&.to_s)
      else
        raise Error, "Unknown package reference in #{package_file_path}:\n  #{local_name}: #{package_defn.inspect}"
      end
      [local_name, package_reference]
    end.to_h
  end
end

#dependency(local_package_name) ⇒ Object

returns a PackageReference



117
118
119
# File 'lib/opswalrus/package_file.rb', line 117

def dependency(local_package_name)
  dependencies[local_package_name]
end

#dirnameObject

def bundle!

bundler_for_package = Bundler.new(dirname)
bundler_for_package.update

end



80
81
82
# File 'lib/opswalrus/package_file.rb', line 80

def dirname
  @package_file_path.dirname
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/opswalrus/package_file.rb', line 88

def eql?(other)
  self.class == other.class && self.hash == other.hash
end

#hashObject



84
85
86
# File 'lib/opswalrus/package_file.rb', line 84

def hash
  @package_file_path.hash
end

#package_fileObject



71
72
73
# File 'lib/opswalrus/package_file.rb', line 71

def package_file
  self
end