Module: GlobalHelpers
- Included in:
- Livetext::Handler::Import, Livetext::Handler::Mixin
- Defined in:
- lib/livetext/global_helpers.rb
Instance Method Summary collapse
- #check_disallowed(name) ⇒ Object
- #check_file_exists(file) ⇒ Object
- #cwd_root? ⇒ Boolean
- #grab_file(fname) ⇒ Object
- #search_upward(file) ⇒ Object
Instance Method Details
#check_disallowed(name) ⇒ Object
4 5 6 7 |
# File 'lib/livetext/global_helpers.rb', line 4 def check_disallowed(name) api.tty "GLOBAL cdis" raise DisallowedName(name) if disallowed?(name) end |
#check_file_exists(file) ⇒ Object
9 10 11 |
# File 'lib/livetext/global_helpers.rb', line 9 def check_file_exists(file) graceful_error FileNotFound(file) unless File.exist?(file) end |
#cwd_root? ⇒ Boolean
38 39 40 |
# File 'lib/livetext/global_helpers.rb', line 38 def cwd_root? File.dirname(File.(".")) == "/" end |
#grab_file(fname) ⇒ Object
13 14 15 |
# File 'lib/livetext/global_helpers.rb', line 13 def grab_file(fname) File.read(fname) end |
#search_upward(file) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/livetext/global_helpers.rb', line 17 def search_upward(file) value = nil return file if File.exist?(file) count = 1 loop do front = "../" * count count += 1 here = Pathname.new(front)..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 |