Module: CodeModels::Serialization
- Defined in:
- lib/codemodels/serialization.rb
Defined Under Namespace
Modules: SerializationFunctionalities
Class Method Summary
collapse
Class Method Details
.load_file(path, max_nesting = 500) ⇒ Object
114
115
116
|
# File 'lib/codemodels/serialization.rb', line 114
def self.load_file(path,max_nesting=500)
JSON.parse(File.read(path),{max_nesting: max_nesting})
end
|
.rgenobject_to_model(root, adapters = {}) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/codemodels/serialization.rb', line 127
def self.rgenobject_to_model(root,adapters={})
model = {}
external_elements = []
sm = SerializationFunctionalities::SerializationMemory.new
model['root'] = root.to_json(memory:sm,adapters:adapters)
model['external_elements'] = []
external_elements.each do |ee|
model['external_elements'] << ee.to_json(memory:sm,adapters:adapters)
end
model
end
|
.save_as_model(root, model_path) ⇒ Object
140
141
142
143
|
# File 'lib/codemodels/serialization.rb', line 140
def self.save_as_model(root,model_path)
model = to_model(root)
save_model(model,model_path)
end
|
.save_model(model, model_path, max_nesting = 500) ⇒ Object
118
119
120
121
122
123
124
125
|
# File 'lib/codemodels/serialization.rb', line 118
def self.save_model(model,model_path,max_nesting=500)
dir = File.dirname(model_path)
FileUtils.mkdir_p(dir)
File.open(model_path, 'w') do |file|
file.write(JSON.pretty_generate(model, :max_nesting => max_nesting))
end
end
|