Sha256: 24623de41b932f31b0e817c6cf4b2fafadba00b12b136b367e6a4a6ccec52711
Contents?: true
Size: 1.42 KB
Versions: 10
Compression:
Stored size: 1.42 KB
Contents
module Animoto module ContentType # When included, includes the InstanceMethods module and extends the # ClassMethods module. def self.included base base.class_eval { include Animoto::ContentType::InstanceMethods extend Animoto::ContentType::ClassMethods } end module InstanceMethods # Returns the content type for this class. # # @return [String] the content type def content_type self.class.content_type end end module ClassMethods # @overload content_type(type) # Sets the content type for this class. # @param [String] content_type the type # @return [String] the content type # @overload content_type() # Returns the content type for this class. # @return [String] the content type def content_type type = nil @content_type = type if type @content_type || infer_content_type end private # If no content type is explicitly set, this will infer the name of the content # type from the class name by lowercasing and underscoring the base name of the # class. For example, Animoto::DirectingJob becomes "directing_job". # # @return [String] the inferred content type def infer_content_type name.split('::').last.gsub(/(^)?([A-Z])/) { "#{'_' unless $1}#{$2.downcase}" } end end end end
Version data entries
10 entries across 10 versions & 1 rubygems