Module: Pru::Helper

Extended by:
Helper
Included in:
Helper
Defined in:
lib/pru/helper.rb

Constant Summary collapse

EXTENSIONS =
['', '.pru', '.rb']

Instance Method Summary collapse

Instance Method Details

#find_file(file, extensions = EXTENSIONS) ⇒ Object


32
33
34
35
36
37
# File 'lib/pru/helper.rb', line 32

def find_file(file, extensions = EXTENSIONS)
  extensions.find { |extension|
    _file = file + extension
    return _file if File.exist?(_file)
  }
end

#load_file(file, type) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pru/helper.rb', line 9

def load_file(file, type)
  if _file = find_file(file)
    file = _file
  else
    home = begin
      require 'nuggets/env/user_home'
      ENV.user_home
    rescue LoadError
      File.expand_path('~')
    end

    if _file = find_file(File.join(home, '.pru', type.to_s, file))
      file = _file
    end
  end

  begin
    File.read(file)
  rescue => err
    abort "#{$0}: #{err}"
  end
end