Class: XCCache::SPM::Package::BaseObject

Inherits:
JSONRepresentable show all
Includes:
Config::Mixin
Defined in:
lib/xccache/spm/desc/base.rb

Direct Known Subclasses

Dependency, Description, Product, Target

Constant Summary collapse

ATTRS =
%i[root retrieve_pkg_desc].freeze

Instance Attribute Summary

Attributes inherited from HashRepresentable

#path, #raw

Instance Method Summary collapse

Methods included from Config::Mixin

#config

Methods inherited from JSONRepresentable

#load, #save

Methods inherited from HashRepresentable

#[], #[]=, #initialize, #load, #merge!, #save

Constructor Details

This class inherits a constructor from XCCache::HashRepresentable

Instance Method Details

#cast_to(cls) ⇒ Object



32
33
34
35
36
# File 'lib/xccache/spm/desc/base.rb', line 32

def cast_to(cls)
  o = cls.new(path, raw: raw)
  ATTRS.each { |sym| o.send("#{sym}=", send(sym.to_s)) }
  o
end

#display_nameObject



24
25
26
# File 'lib/xccache/spm/desc/base.rb', line 24

def display_name
  name
end

#fetch(key, dtype) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/xccache/spm/desc/base.rb', line 46

def fetch(key, dtype)
  raw[key].map do |h|
    o = dtype.new(nil, raw: h)
    o.root = root
    o.retrieve_pkg_desc = retrieve_pkg_desc
    o
  end
end

#full_nameObject



16
17
18
# File 'lib/xccache/spm/desc/base.rb', line 16

def full_name
  is_a?(Description) ? name : "#{pkg_slug}/#{name}"
end

#inspectObject



20
21
22
# File 'lib/xccache/spm/desc/base.rb', line 20

def inspect
  to_s
end

#nameObject



12
13
14
# File 'lib/xccache/spm/desc/base.rb', line 12

def name
  raw["name"]
end

#pkg_desc_of(name) ⇒ Object



55
56
57
# File 'lib/xccache/spm/desc/base.rb', line 55

def pkg_desc_of(name)
  retrieve_pkg_desc.call(name)
end

#pkg_nameObject



38
39
40
# File 'lib/xccache/spm/desc/base.rb', line 38

def pkg_name
  @pkg_name ||= root.name
end

#pkg_slugObject



42
43
44
# File 'lib/xccache/spm/desc/base.rb', line 42

def pkg_slug
  @pkg_slug ||= src_dir.basename.to_s
end

#src_dirObject



59
60
61
62
63
64
# File 'lib/xccache/spm/desc/base.rb', line 59

def src_dir
  @src_dir ||= begin
    path = root.raw.fetch("packageKind", {}).fetch("root", [])[0]
    Pathname.new(path) unless path.nil?
  end
end

#to_sObject



28
29
30
# File 'lib/xccache/spm/desc/base.rb', line 28

def to_s
  "<#{self.class} name=#{display_name}>"
end