Module: CodeModels::Serialization
- Defined in:
- lib/codemodels/serialization.rb
Overview
Everything related to serialization to Hash, lists and basic values is contained in this module
Defined Under Namespace
Modules: SerializationFunctionalities
Class Method Summary
collapse
Class Method Details
.load_file(path, max_nesting = 500) ⇒ Object
122
123
124
|
# File 'lib/codemodels/serialization.rb', line 122
def self.load_file(path,max_nesting=500)
JSON.parse(File.read(path),{max_nesting: max_nesting})
end
|
.rgenobject_to_model(root, adapters = {}) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/codemodels/serialization.rb', line 135
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
148
149
150
151
|
# File 'lib/codemodels/serialization.rb', line 148
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
126
127
128
129
130
131
132
133
|
# File 'lib/codemodels/serialization.rb', line 126
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
|