Class: JsonRefs::Loader
- Inherits:
-
Object
- Object
- JsonRefs::Loader
- Defined in:
- lib/json_refs/loader.rb
Defined Under Namespace
Constant Summary collapse
- EXTENSIONS =
{ 'json' => JsonRefs::Loader::Json, 'yaml' => JsonRefs::Loader::Yaml, 'yml' => JsonRefs::Loader::Yaml, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.handle(filename) ⇒ Object
25 26 27 |
# File 'lib/json_refs/loader.rb', line 25 def self.handle(filename) new.handle(filename) end |
Instance Method Details
#handle(filename) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/json_refs/loader.rb', line 29 def handle(filename) @body = read_reference_file(filename) ext = File.extname(filename)[1..-1] ext ||= 'json' if json?(@body) ext && EXTENSIONS.include?(ext) ? EXTENSIONS[ext].new.call(@body) : @body end |
#json?(file_body) ⇒ Boolean
36 37 38 39 40 41 |
# File 'lib/json_refs/loader.rb', line 36 def json?(file_body) JSON.load(file_body) true rescue JSON::ParserError => e false end |