Sha256: e166775c78a4996252b18839d783dca3de90d1a39f8e675cf5978b9c5be53db0

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

#
# This file was ported to ruby from Composer php source code.
# Original Source: Composer\Package\Loader\JsonLoader.php
#
# (c) Nils Adermann <naderman@naderman.de>
#     Jordi Boggiano <j.boggiano@seld.be>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#

module Composer
  module Package
    module Loader

      # Loads a package from a json string or JsonFile
      # @author Ioannis Kappas <ikappas@devworks.gr>
      # @php_author Konstantin Kudryashiv <ever.zet@gmail.com>
      class JsonLoader

        def initialize(loader)
          @loader = loader
        end

        # 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
        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

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
php-composer-0.4.5 lib/composer/package/loader/json_loader.rb
php-composer-0.4.4 lib/composer/package/loader/json_loader.rb
php-composer-0.4.3 lib/composer/package/loader/json_loader.rb
php-composer-0.4.2 lib/composer/package/loader/json_loader.rb
php-composer-0.4.1 lib/composer/package/loader/json_loader.rb
php-composer-0.4.0 lib/composer/package/loader/json_loader.rb