Class: YASL::Loader
- Inherits:
-
Object
- Object
- YASL::Loader
- Defined in:
- lib/yasl/loader.rb
Instance Attribute Summary collapse
-
#class_objects ⇒ Object
readonly
Returns the value of attribute class_objects.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
-
#whitelist_classes ⇒ Object
readonly
Returns the value of attribute whitelist_classes.
Instance Method Summary collapse
-
#initialize(structure, whitelist_classes: []) ⇒ Loader
constructor
A new instance of Loader.
- #load(include_classes: false) ⇒ Object
- #load_classes_structure ⇒ Object
- #load_structure(structure, for_classes: false) ⇒ Object
Constructor Details
#initialize(structure, whitelist_classes: []) ⇒ Loader
Returns a new instance of Loader.
26 27 28 29 30 |
# File 'lib/yasl/loader.rb', line 26 def initialize(structure, whitelist_classes: []) @structure = structure @whitelist_classes = whitelist_classes @class_objects = {} end |
Instance Attribute Details
#class_objects ⇒ Object (readonly)
Returns the value of attribute class_objects.
24 25 26 |
# File 'lib/yasl/loader.rb', line 24 def class_objects @class_objects end |
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
24 25 26 |
# File 'lib/yasl/loader.rb', line 24 def structure @structure end |
#whitelist_classes ⇒ Object (readonly)
Returns the value of attribute whitelist_classes.
24 25 26 |
# File 'lib/yasl/loader.rb', line 24 def whitelist_classes @whitelist_classes end |
Instance Method Details
#load(include_classes: false) ⇒ Object
32 33 34 35 36 |
# File 'lib/yasl/loader.rb', line 32 def load(include_classes: false) load_structure(structure).tap do load_classes_structure if include_classes end end |
#load_classes_structure ⇒ Object
38 39 40 41 42 |
# File 'lib/yasl/loader.rb', line 38 def load_classes_structure structure['_classes'].to_a.each do |class_structure| load_non_basic_data_type_object(class_structure, for_classes: true) end end |
#load_structure(structure, for_classes: false) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/yasl/loader.rb', line 44 def load_structure(structure, for_classes: false) if top_level_class?(structure) class_for(structure['_class']) elsif YASL.json_basic_data_type?(structure) && !(structure.is_a?(String) && structure.start_with?('_')) structure elsif ruby_basic_data_type_structure?(structure) load_ruby_basic_data_type_object(structure['_class'], structure['_data']) elsif load_non_basic_data_type_structure?(structure) load_non_basic_data_type_object(structure) end end |