Sha256: c8a973b7d805f574de475cadbbec6aa311dd4fe8326a1d5ce09ac93c1037a630

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 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 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

3 entries across 3 versions & 1 rubygems

Version Path
praxis-2.0.pre.4 lib/praxis/types/media_type_common.rb
praxis-2.0.pre.3 lib/praxis/types/media_type_common.rb
praxis-2.0.pre.2 lib/praxis/types/media_type_common.rb