Module: Rpub::FilesystemSource

Defined in:
lib/rpub/filesystem_source.rb

Class Method Summary collapse

Class Method Details

.exists?(filename) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/rpub/filesystem_source.rb', line 9

def exists?(filename)
  File.exists?(filename)
end

.force_write(filename, content) ⇒ Object



28
29
30
# File 'lib/rpub/filesystem_source.rb', line 28

def force_write(filename, content)
  write filename, content, true
end

.own_or_support_file(filename) ⇒ Object



42
43
44
45
# File 'lib/rpub/filesystem_source.rb', line 42

def own_or_support_file(filename)
  return filename if exists?(filename)
  Rpub.support_file(filename)
end

.read(filename) ⇒ Object



5
6
7
# File 'lib/rpub/filesystem_source.rb', line 5

def read(filename)
  File.read(filename)
end

.remove(filename, dry_run = false) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/rpub/filesystem_source.rb', line 32

def remove(filename, dry_run = false)
  if File.exist?(filename)
    if dry_run
      puts filename
    else
      File.unlink(filename)
    end
  end
end

.source_filesObject



13
14
15
# File 'lib/rpub/filesystem_source.rb', line 13

def source_files
  Dir['*{.md,.markdown,.mdown,.markd}']
end

.write(filename, content, force = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/rpub/filesystem_source.rb', line 17

def write(filename, content, force = false)
  return if content.nil?
  if !force && File.exist?(filename)
    warn "Not overriding #{filename}"
    return
  end
  File.open(filename, 'w') do |f|
    f.write content
  end
end