Class: Rack::Combobot::Combination
- Inherits:
-
Object
- Object
- Rack::Combobot::Combination
- Defined in:
- lib/rack/combobot/combination.rb
Defined Under Namespace
Classes: PathError
Instance Method Summary collapse
- #combine ⇒ Object
- #fetch_file_contents(file_names = []) ⇒ Object
-
#initialize(root, file_names) ⇒ Combination
constructor
A new instance of Combination.
Constructor Details
#initialize(root, file_names) ⇒ Combination
Returns a new instance of Combination.
6 7 8 9 10 |
# File 'lib/rack/combobot/combination.rb', line 6 def initialize(root, file_names) @root = root @file_contents = fetch_file_contents file_names if file_names end |
Instance Method Details
#combine ⇒ Object
26 27 28 |
# File 'lib/rack/combobot/combination.rb', line 26 def combine @combo ||= @file_contents.join end |
#fetch_file_contents(file_names = []) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rack/combobot/combination.rb', line 12 def fetch_file_contents(file_names = []) file_names.map do |file_name| raise PathError if file_name.include?('..') || file_name.include?("~") root_prefix = ::File.(".", @root) + "/" file_path = ::File.(file_name, @root) raise PathError unless file_path.start_with?(root_prefix) && ::File.exist?(file_path) file_content = ::File.open(file_path, 'r') { |f| f.read } end end |