Class: Rwm::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/rwm/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, path:, type:) ⇒ Package

Returns a new instance of Package.



10
11
12
13
14
# File 'lib/rwm/package.rb', line 10

def initialize(name:, path:, type:)
  @name = name
  @path = File.expand_path(path)
  @type = type.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/rwm/package.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/rwm/package.rb', line 8

def path
  @path
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/rwm/package.rb', line 8

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



53
54
55
# File 'lib/rwm/package.rb', line 53

def ==(other)
  other.is_a?(Package) && name == other.name && path == other.path
end

#app?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rwm/package.rb', line 20

def app?
  type == :app
end

#gemfile_pathObject



37
38
39
# File 'lib/rwm/package.rb', line 37

def gemfile_path
  File.join(path, "Gemfile")
end

#gemspec_pathObject



41
42
43
# File 'lib/rwm/package.rb', line 41

def gemspec_path
  Dir.glob(File.join(path, "*.gemspec")).first
end

#has_rake_task?(task) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
# File 'lib/rwm/package.rb', line 28

def has_rake_task?(task)
  return false unless has_rakefile?

  output, _, status = Open3.capture3("bundle", "exec", "rake", "-P", chdir: path)
  return false unless status.success?

  output.lines.any? { |line| line.strip == "rake #{task}" }
end

#has_rakefile?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rwm/package.rb', line 24

def has_rakefile?
  File.exist?(File.join(path, "Rakefile"))
end

#hashObject



58
59
60
# File 'lib/rwm/package.rb', line 58

def hash
  [name, path].hash
end

#lib?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rwm/package.rb', line 16

def lib?
  type == :lib
end

#relative_path(workspace_root) ⇒ Object



45
46
47
# File 'lib/rwm/package.rb', line 45

def relative_path(workspace_root)
  Pathname.new(path).relative_path_from(Pathname.new(workspace_root)).to_s
end

#to_sObject



49
50
51
# File 'lib/rwm/package.rb', line 49

def to_s
  "#{name} (#{type})"
end