Class: Spellr::File

Inherits:
Pathname
  • Object
show all
Defined in:
lib/spellr/file.rb

Instance Method Summary collapse

Instance Method Details

#first_lineObject

the bulk of this method is copied from fast_ignore



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spellr/file.rb', line 19

def first_line # rubocop:disable Metrics/MethodLength
  return @first_line if defined?(@first_line)

  @first_line = nil

  file = ::File.new(to_s)
  @first_line = file.sysread(25)
  @first_line += file.sysread(50) until @first_line.include?("\n")
  file.close
  @first_line
rescue ::EOFError, ::SystemCallError
  # :nocov:
  file&.close
  # :nocov:
  @first_line
end

#insert(string, range) ⇒ Object



11
12
13
14
15
16
# File 'lib/spellr/file.rb', line 11

def insert(string, range)
  read_write do |body|
    body[range] = string
    body
  end
end

#read_writeObject



36
37
38
# File 'lib/spellr/file.rb', line 36

def read_write
  write(yield read)
end

#relative_pathObject



7
8
9
# File 'lib/spellr/file.rb', line 7

def relative_path
  @relative_path ||= relative_path_from(Spellr.pwd)
end

#wordlistsObject



40
41
42
# File 'lib/spellr/file.rb', line 40

def wordlists
  ::Spellr.config.wordlists_for(self).sort_by { |wordlist| -wordlist.length }
end