Module: GlobalHelpers

Included in:
Livetext::Handler::Import, Livetext::Handler::Mixin
Defined in:
lib/livetext/global_helpers.rb

Instance Method Summary collapse

Instance Method Details

#check_disallowed(name) ⇒ Object



4
5
6
# File 'lib/livetext/global_helpers.rb', line 4

def check_disallowed(name)
  raise DisallowedName(name) if disallowed?(name)
end

#check_file_exists(file) ⇒ Object



8
9
10
# File 'lib/livetext/global_helpers.rb', line 8

def check_file_exists(file)
  graceful_error FileNotFound(file) unless File.exist?(file)
end

#cwd_root?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/livetext/global_helpers.rb', line 37

def cwd_root?
  File.dirname(File.expand_path(".")) == "/"
end

#grab_file(fname) ⇒ Object



12
13
14
# File 'lib/livetext/global_helpers.rb', line 12

def grab_file(fname)
  File.read(fname)
end

#search_upward(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/livetext/global_helpers.rb', line 16

def search_upward(file)
  value = nil
  return file if File.exist?(file)

  count = 1
  loop do
    front = "../" * count
    count += 1
    here = Pathname.new(front).expand_path.dirname.to_s
    break if here == "/"
    path = front + file
    value = path if File.exist?(path)
    break if value
  end
  ::STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
 return value
rescue
  ::STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
 return nil
end