Class: Composer::Package::Loader::JsonLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/composer/package/loader/json_loader.rb

Overview

Loads a package from a json string or JsonFile

Author:

Instance Method Summary collapse

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