Module: KeyValueName::FileName::InstanceMethods

Includes:
Name::InstanceMethods
Defined in:
lib/key_value_name/mixins/file_name.rb

Overview

Instance method mixin for a file.

Instance Attribute Summary

Attributes included from Name::InstanceMethods

#parent

Instance Method Summary collapse

Methods included from Name::InstanceMethods

#<=>, #to_s

Instance Method Details

#destroy!Object



38
39
40
# File 'lib/key_value_name/mixins/file_name.rb', line 38

def destroy!
  FileUtils.rm_f(to_s)
end

#exist?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/key_value_name/mixins/file_name.rb', line 13

def exist?
  File.exist?(to_s)
end

#mkdir!self

Ensure that the parent folder exists.

Returns:

  • (self)


22
23
24
25
# File 'lib/key_value_name/mixins/file_name.rb', line 22

def mkdir!
  parent.mkdir!
  self
end

#touch!Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/key_value_name/mixins/file_name.rb', line 27

def touch!
  retried ||= false
  FileUtils.touch(to_s)
  self
rescue Errno::ENOENT
  FileUtils.mkdir_p(File.dirname(to_s))
  raise if retried
  retried = true
  retry
end