Class: Rwm::Package
- Inherits:
-
Object
- Object
- Rwm::Package
- Defined in:
- lib/rwm/package.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #app? ⇒ Boolean
- #gemfile_path ⇒ Object
- #gemspec_path ⇒ Object
- #has_rake_task?(task) ⇒ Boolean
- #has_rakefile? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, path:, type:) ⇒ Package
constructor
A new instance of Package.
- #lib? ⇒ Boolean
- #relative_path(workspace_root) ⇒ Object
- #to_s ⇒ Object
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.(path) @type = type.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/rwm/package.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/rwm/package.rb', line 8 def path @path end |
#type ⇒ Object (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
20 21 22 |
# File 'lib/rwm/package.rb', line 20 def app? type == :app end |
#gemfile_path ⇒ Object
37 38 39 |
# File 'lib/rwm/package.rb', line 37 def gemfile_path File.join(path, "Gemfile") end |
#gemspec_path ⇒ Object
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
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
24 25 26 |
# File 'lib/rwm/package.rb', line 24 def has_rakefile? File.exist?(File.join(path, "Rakefile")) end |
#hash ⇒ Object
58 59 60 |
# File 'lib/rwm/package.rb', line 58 def hash [name, path].hash end |
#lib? ⇒ 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_s ⇒ Object
49 50 51 |
# File 'lib/rwm/package.rb', line 49 def to_s "#{name} (#{type})" end |