Class: Packs::Pack

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/packs/pack.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, path:, relative_path:) ⇒ Pack

Returns a new instance of Pack.



17
18
19
20
21
22
23
# File 'lib/packs/pack.rb', line 17

def initialize(name:, path:, relative_path:)
  @name = name
  @path = path
  @relative_path = relative_path
  @raw_hash = T.let(nil, T.nilable(T::Hash[T.untyped, T.untyped]))
  @is_gem = T.let(nil, T.nilable(T::Boolean))
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/packs/pack.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/packs/pack.rb', line 11

def path
  @path
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



14
15
16
# File 'lib/packs/pack.rb', line 14

def relative_path
  @relative_path
end

Class Method Details

.from(package_yml_absolute_path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/packs/pack.rb', line 26

def self.from(package_yml_absolute_path)
  path = package_yml_absolute_path.dirname
  relative_path = path.relative_path_from(Specification.root)
  package_name = relative_path.cleanpath.to_s

  Pack.new(
    name: package_name,
    path: path,
    relative_path: relative_path
  )
end

Instance Method Details

#inspectObject



69
70
71
72
73
74
# File 'lib/packs/pack.rb', line 69

def inspect
  ivars = instance_variables_to_inspect.map do |ivar|
    "#{ivar}=#{instance_variable_get(ivar).inspect}"
  end.join(', ')
  "#<#{self.class.name}:0x#{object_id.to_s(16)} #{ivars}>"
end

#is_gem?Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)


55
56
57
# File 'lib/packs/pack.rb', line 55

def is_gem? # rubocop:disable Naming/PredicateName
  @is_gem ||= relative_path.glob('*.gemspec').any?
end

#last_nameObject



50
51
52
# File 'lib/packs/pack.rb', line 50

def last_name
  relative_path.basename.to_s
end

#metadataObject



60
61
62
# File 'lib/packs/pack.rb', line 60

def 
  raw_hash['metadata'] || {}
end

#raw_hashObject



39
40
41
# File 'lib/packs/pack.rb', line 39

def raw_hash
  @raw_hash ||= YAML.load_file(yml(relative: false)) || {}
end

#yml(relative: true) ⇒ Object



44
45
46
47
# File 'lib/packs/pack.rb', line 44

def yml(relative: true)
  path_to_use = relative ? relative_path : path
  path_to_use.join(PACKAGE_FILE).cleanpath
end