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
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
60
61
62
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 60
def descendants_paths
[]
end
|
#load_data ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 47
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
28
29
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 25
def save(data)
abs_dir = File.dirname(save_file_path)
FileUtils.mkdir_p(abs_dir) unless FileTest.exists?(abs_dir)
File.write(save_file_path, data)
end
|
#save_after_deep_merge(data) ⇒ Object
31
32
33
34
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 31
def save_after_deep_merge(data)
result = load_data.deep_merge(data)
save(result.to_yaml)
end
|
#save_file_path(type: :full) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/r2-oas/schema/v3/manager/file/base_file_manager.rb', line 36
def save_file_path(type: :full)
file_path = File.expand_path(@relative_save_file_path)
case type
when :relative
file_path.sub(%r{^#{Dir.getwd}/?}, '')
else
file_path
end
end
|