Class: Rebundler::GemDeclaration

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rebundler/gem_declaration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node: nil) ⇒ GemDeclaration

Returns a new instance of GemDeclaration.



9
10
11
# File 'lib/rebundler/gem_declaration.rb', line 9

def initialize(node: nil)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



7
8
9
# File 'lib/rebundler/gem_declaration.rb', line 7

def node
  @node
end

Instance Method Details

#<=>(other) ⇒ Object



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

def <=>(other)
  unless other.is_a?(GemDeclaration)
    raise ArgumentError,
          "comparison of GemDeclaration with #{other.class} failed"
  end

  normalized_name <=> other.normalized_name
end

#nameObject



13
# File 'lib/rebundler/gem_declaration.rb', line 13

def name = @node.arguments.child_nodes[0].content

#normalized_nameObject



14
# File 'lib/rebundler/gem_declaration.rb', line 14

def normalized_name = name.tr("-_", "").downcase

#summaryObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rebundler/gem_declaration.rb', line 16

def summary
  gem = find_loaded_gem || find_external_gem

  return if gem.nil?

  if gem.summary.nil? || gem.summary == ""
    gem.description
  else
    gem.summary
  end
end