Sha256: a9a22a90051c7090fd10e7c980ef6884baf6baa0eaac77057c610dc247cc8993

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module GrapeApiary
  class Config
    SETTINGS = [
      :host,
      :name,
      :description,
      :request_headers,
      :response_headers,
      :example_id_type,
      :resource_exclusion
    ]

    class << self
      attr_accessor(*SETTINGS)

      def request_headers
        @request_headers ||= []
      end

      def response_headers
        @response_headers ||= []
      end

      def resource_exclusion
        @resource_exclusion ||= []
      end

      def supported_id_types
        [:integer, :uuid, :bson]
      end

      def example_id_type=(value)
        fail UnsupportedIDType unless supported_id_types.include?(value)

        if value.to_sym == :bson && !Object.const_defined?('BSON')
          fail BSONNotDefinied
        end

        @example_id_type = value
      end

      def example_id_type
        @example_id_type ||= :integer
      end

      def generate_id
        case example_id_type
        when :integer
          SecureRandom.random_number(1000)
        when :uuid
          SecureRandom.uuid
        when :bson
          BSON::ObjectId.new.to_s
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-apiary-0.0.4 lib/grape-apiary/config.rb
grape-apiary-0.0.3 lib/grape-apiary/config.rb