Class: Show::Gem::Junk::GemFile

Inherits:
Object
  • Object
show all
Defined in:
lib/show/gem/junk/gemfile.rb

Overview

GemFile is a file that belongs to a rubygem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GemFile

Returns a new instance of GemFile.



9
10
11
12
# File 'lib/show/gem/junk/gemfile.rb', line 9

def initialize(path)
  @path = path
  @stat = File.stat(path)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/show/gem/junk/gemfile.rb', line 7

def path
  @path
end

#statObject

Returns the value of attribute stat.



7
8
9
# File 'lib/show/gem/junk/gemfile.rb', line 7

def stat
  @stat
end

Instance Method Details

#<=>(other) ⇒ Object



22
23
24
# File 'lib/show/gem/junk/gemfile.rb', line 22

def <=>(other)
  size <=> other.size
end

#junk?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/show/gem/junk/gemfile.rb', line 26

def junk?
  return false if File.directory?(path)

  basename = File.basename(path)

  # Files
  return true if basename.end_with?('.gemspec')
  return true if basename == '.gitignore'
  return true if basename == '.travis.yml'
  return true if basename == '.appveyor.yml'

  # Loose path matching
  return true if path.include?('concourse')

  # Specs
  parts = Pathname.new(pretty_path).each_filename.to_a
  return false if parts.size < 2
  return true if parts[1] == 'test'
  return true if parts[1] == 'spec'
  return true if parts[1] == 'features'

  false
end

#pretty_pathObject



18
19
20
# File 'lib/show/gem/junk/gemfile.rb', line 18

def pretty_path
  path.gsub(GEMS_DIR, '')
end

#sizeObject



14
15
16
# File 'lib/show/gem/junk/gemfile.rb', line 14

def size
  stat.size
end