Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Add singleton file_path method to contents resolved by include #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/raml/node/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def interpolate(params)

def clone_data
# ugly but effective
Marshal.load Marshal.dump @value
Marshal.load Marshal.dump @value.dup
end

def interpolate_params(value, params)
Expand Down
2 changes: 2 additions & 0 deletions lib/raml/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def expand_includes_transform(cwd)

if val.is_a? Raml::Parser::Include
child_wd = expand_includes_working_dir cwd, val.path
path = val.path
val = val.content cwd
val.define_singleton_method(:file_path) { child_wd + "/" + path.split("/").last }
end

expand_includes val, child_wd
Expand Down
8 changes: 7 additions & 1 deletion test/raml/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
root.schemas['Test' ].value.should eq 'test_schema'
root.schemas['File' ].value.should eq 'file_schema'
end


it "inserts singleton method to read the file_path" do
file = File.new 'fixtures/include_1.raml'
root = Raml::Parser.parse file.read, 'fixtures'
root.schemas['FileUpdate'].value.file_path.should eq 'fixtures/schemas/filesystem/fileupdate.json'
end

context 'when the included file is not redable' do
it do
expect { Raml::Parser.parse('- !include does_not_exit') }.to raise_error Raml::CantIncludeFile
Expand Down