Class: OasDivider::PathsObject
- Inherits:
-
Object
- Object
- OasDivider::PathsObject
- Defined in:
- lib/oas_divider/paths_object.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#path_item_objects ⇒ Object
Returns the value of attribute path_item_objects.
Instance Method Summary collapse
- #convert_ref ⇒ Object
- #directory ⇒ Object
- #file_name ⇒ Object
-
#initialize(path, path_item_objects) ⇒ PathsObject
constructor
A new instance of PathsObject.
- #interlevel_directory ⇒ Object
- #make_directory ⇒ Object
- #ref ⇒ Object
- #to_file ⇒ Object
Constructor Details
#initialize(path, path_item_objects) ⇒ PathsObject
Returns a new instance of PathsObject.
5 6 7 8 |
# File 'lib/oas_divider/paths_object.rb', line 5 def initialize(path, path_item_objects) @path = path @path_item_objects = path_item_objects end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/oas_divider/paths_object.rb', line 3 def path @path end |
#path_item_objects ⇒ Object
Returns the value of attribute path_item_objects.
3 4 5 |
# File 'lib/oas_divider/paths_object.rb', line 3 def path_item_objects @path_item_objects end |
Instance Method Details
#convert_ref ⇒ Object
39 40 41 |
# File 'lib/oas_divider/paths_object.rb', line 39 def convert_ref RelativeDocumentReferencer.execute(path_item_objects, 1 + interlevel_directory.size) end |
#directory ⇒ Object
27 28 29 |
# File 'lib/oas_divider/paths_object.rb', line 27 def directory File.join( 'paths' , interlevel_directory) end |
#file_name ⇒ Object
31 32 33 |
# File 'lib/oas_divider/paths_object.rb', line 31 def file_name "#{@path.split('/').pop.gsub(/[{}]/,"")}.yml" end |
#interlevel_directory ⇒ Object
23 24 25 |
# File 'lib/oas_divider/paths_object.rb', line 23 def interlevel_directory @path.split('/').length > 2 ? @path.split('/')[1..-2].map {|dir| dir.gsub(/[{}]/,"")} : '' end |
#make_directory ⇒ Object
16 17 18 19 20 21 |
# File 'lib/oas_divider/paths_object.rb', line 16 def make_directory FileUtils.mkdir_p( directory ) rescue => e puts "path: #{@path}" throw e end |
#ref ⇒ Object
35 36 37 |
# File 'lib/oas_divider/paths_object.rb', line 35 def ref File.join(directory, file_name) end |
#to_file ⇒ Object
10 11 12 13 14 |
# File 'lib/oas_divider/paths_object.rb', line 10 def to_file make_directory convert_ref YAML.dump(path_item_objects, File.open( File.join(directory, file_name) , 'w') ) end |