Class: Philosophal::Loaders::JsonLoader
- Inherits:
-
Object
- Object
- Philosophal::Loaders::JsonLoader
- Defined in:
- lib/philosophal/loaders/json_loader.rb
Instance Method Summary collapse
-
#initialize(klass) ⇒ JsonLoader
constructor
A new instance of JsonLoader.
- #load(json) ⇒ Object
Constructor Details
#initialize(klass) ⇒ JsonLoader
Returns a new instance of JsonLoader.
6 7 8 |
# File 'lib/philosophal/loaders/json_loader.rb', line 6 def initialize(klass) @klass = klass end |
Instance Method Details
#load(json) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/philosophal/loaders/json_loader.rb', line 10 def load(json) return load_from_hash(json) if json.is_a?(Hash) return load_from_array(json) if json.is_a?(Array) raise LoadError, 'invalid json parameter' unless json.is_a?(String) first_char = json[0] return load_from_json(json) if first_char == '{' return load_from_json_collection(json) if first_char == '[' load_from_path(json) end |