Class: Composer::Package::Loader::JsonLoader
- Inherits:
-
Object
- Object
- Composer::Package::Loader::JsonLoader
- Defined in:
- lib/composer/package/loader/json_loader.rb
Overview
Loads a package from a json string or JsonFile
Instance Method Summary collapse
-
#initialize(loader) ⇒ JsonLoader
constructor
A new instance of JsonLoader.
-
#load(json) ⇒ Object
Load a json string or file Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from Returns: Composer::Package::Package.
Constructor Details
#initialize(loader) ⇒ JsonLoader
Returns a new instance of JsonLoader.
21 22 23 |
# File 'lib/composer/package/loader/json_loader.rb', line 21 def initialize(loader) @loader = loader end |
Instance Method Details
#load(json) ⇒ Object
Load a json string or file Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from Returns: Composer::Package::Package
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/composer/package/loader/json_loader.rb', line 28 def load(json) if json.instance_of?(Composer::Json::JsonFile) config = json.read elsif File.exists?(json) config = Composer::Json::JsonFile.parse_json( File.open(filepath, "r") { |f| f.read }, json ) elsif json.class === "String" config = Composer::Json::JsonFile.parse_json( json ) end @loader.load(config) end |