Class: R2OAS::Schema::V3::BaseFileManager
- Inherits:
-
Base
show all
- Defined in:
- lib/r2-oas/schema/v3/manager/file/base_file_manager.rb
Constant Summary
Constants inherited
from Base
R2OAS::Schema::V3::Base::SUPPORT_COMPONENTS_OBJECTS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#support_components_objects
Constructor Details
#initialize(path, path_type = :full) ⇒ BaseFileManager
e.x.) openapi_path = “#/components/schemas/Account”
13
14
15
16
17
18
19
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 13
def initialize(path, path_type = :full)
super()
@ext_name = :yml
@path_type = path_type
@original_path = path
@relative_save_file_path = PathnameManager.new(path, path_type).relative_save_file_path
end
|
Instance Attribute Details
#original_path ⇒ Object
Returns the value of attribute original_path.
10
11
12
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 10
def original_path
@original_path
end
|
Instance Method Details
#delete ⇒ Object
21
22
23
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 21
def delete
File.delete(save_file_path) if FileTest.exists?(save_file_path)
end
|
#descendants_paths ⇒ Object
54
55
56
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 54
def descendants_paths
[]
end
|
#load_data ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 41
def load_data
case @ext_name
when :yml
if FileTest.exists?(save_file_path)
YAML.load_file(save_file_path)
else
{}
end
else
raise NoSupportError, "Do not support @ext_name: #{@ext_name}"
end
end
|
#save(data) ⇒ Object
25
26
27
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 25
def save(data)
File.write(save_file_path, data)
end
|
#save_after_deep_merge(data) ⇒ Object
29
30
31
32
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 29
def save_after_deep_merge(data)
result = load_data.deep_merge(data)
save(result.to_yaml)
end
|
#save_file_path ⇒ Object
34
35
36
37
38
39
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 34
def save_file_path
File.expand_path(@relative_save_file_path).tap do |abs_path|
abs_dir = File.dirname(abs_path)
FileUtils.mkdir_p(abs_dir) unless FileTest.exists?(abs_dir)
end
end
|