Sha256: 11588f6ff56ae74f575a74f5836f68d9a21a03e3f8cc13cb6f2d19ad1281482a

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

module Rambo
  module RamlModels
    class Api
      attr_reader :schema, :options

      def initialize(parsed_raml, options={})
        @schema, @options = parsed_raml, options
      end

      def resources
        @resources ||= schema.resources.map {|resource| Rambo::RamlModels::Resource.new(resource, headers) }
      end

      def title
        @title ||= schema.title
      end

      def security_schemes
        @security_schemes ||= schema.security_schemes.map {|scheme| Rambo::RamlModels::SecurityScheme.new(scheme, options) }
      end

      def headers
        @headers ||= Rambo::RamlModels::Headers.new({})

        add_content_type_header!(@headers)
        add_security_headers!(@headers)

        @headers
      end

      private

      def add_content_type_header!(h)
        h.add({ "Content-Type" => schema.media_type }) if schema.media_type
      end

      def add_security_headers!(h)
        return unless schema.secured_by

        scheme = security_schemes.find {|sch| sch.title == schema.secured_by.first }

        h.merge!(scheme.headers)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rambo_ruby-0.7.1 lib/rambo/raml_models/api.rb
rambo_ruby-0.7.0 lib/rambo/raml_models/api.rb
rambo_ruby-0.6.0 lib/rambo/raml_models/api.rb
rambo_ruby-0.5.0 lib/rambo/raml_models/api.rb
rambo_ruby-0.4.0 lib/rambo/raml_models/api.rb
rambo_ruby-0.3.3 lib/rambo/raml_models/api.rb
rambo_ruby-0.3.2 lib/rambo/raml_models/api.rb
rambo_ruby-0.3.1 lib/rambo/raml_models/api.rb
rambo_ruby-0.3.0 lib/rambo/raml_models/api.rb