Sha256: 38d13c38b9eecf0a9573d642004e903ec81f42e216725e76c154effd15259e23

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

module Praxis
  module Types

    # Traits that are shared by MediaType and SimpleMediaType.
    module MediaTypeCommon
      extend ::ActiveSupport::Concern

      module ClassMethods
        def describe(shallow = false, **opts)
          hash = super
          unless shallow
            hash.merge!(identifier: @identifier.to_s, description: @description, display_name: self.display_name)
          end
          hash
        end

        def as_json_schema(**args)
          the_type = @attribute && @attribute.type || member_type
          the_type.as_json_schema(args)
        end

        def json_schema_type
          the_type = @attribute && @attribute.type || member_type
          the_type.json_schema_type
        end
    
        def description(text=nil)
          @description = text if text
          @description
        end

        def display_name( string=nil )
          unless string
            return  @display_name ||= self.name.split("::").last  # Best guess at a display name?
          end
          @display_name = string
        end

        # Get or set the identifier of this media type.
        #
        # @deprecated this method is not deprecated, but its return type will change to MediaTypeIdentifier in Praxis 1.0
        #
        # @return [String] the string-representation of this type's identifier
        def identifier(identifier=nil)
          return @identifier unless identifier
          @identifier = MediaTypeIdentifier.load(identifier)
        end
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
praxis-2.0.pre.9 lib/praxis/types/media_type_common.rb
praxis-2.0.pre.8 lib/praxis/types/media_type_common.rb
praxis-2.0.pre.7 lib/praxis/types/media_type_common.rb
praxis-2.0.pre.6 lib/praxis/types/media_type_common.rb
praxis-2.0.pre.5 lib/praxis/types/media_type_common.rb