Sha256: e32afbae14088ab366cb92eac61a3a9b2077aa3f678c3279c7a70ed63639a2f3

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

module Rod
  module Rest
    class Metadata
      ROD_KEY = /\ARod\b/

      attr_reader :description

      # Initializes the metadata via the options:
      # * description - text representation of the metadata
      # * parser - parser used to parse the text representation of the metadata
      # * resource_metadata_factory - factory used to create metadata for the
      #   resources
      def initialize(options={})
        @description = options.fetch(:description)
        parser = options[:parser] || JSON
        @resource_metadata_factory = options[:resource_metadata_factory] || ResourceMetadata
        @resources = create_resource_descriptions(parser.parse(@description, symbolize_names: true))
      end

      # Return collection of resource metadata.
      def resources
        @resources
      end

      private
      def create_resource_descriptions(hash_description)
        hash_description.map do |name,description|
          next if restricted_name?(name)
          @resource_metadata_factory.new(name,description)
        end.compact
      end

      def restricted_name?(name)
        name.to_s =~ ROD_KEY
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rod-rest-0.0.1.1 lib/rod/rest/metadata.rb
rod-rest-0.0.1 lib/rod/rest/metadata.rb