Sha256: d455bc6d54b129430aa6f02ac203cbc7252a98210b58616c6bc292ab7a1485c9

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

# @private
class Skyline::Content::Implementation
  extend ActiveSupport::Memoizable
  include Singleton
  
  # All the content_classes. This works fine when using in Rails
  # as the implementation instance get's reloaded on each request. Make sure to reset
  # the cache if the classes change.
  def content_classes
    return @_contentclasses if @_contentclasses

    do_not_include = []
    @_contentclasses = Skyline::Configuration.content_classes.collect do |klass|
      klass = klass.kind_of?(Class) ? klass : klass.to_s.constantize
      if klass.respond_to?(:content?) && klass.content? && !klass.abstract_class
        klass.reflect_on_all_associations(:has_many).each do |assoc|
          # Do not include associated classes unless it's self-referential
          if assoc.klass && assoc.klass != klass && !assoc.through_reflection
            do_not_include << assoc.klass 
          end
        end
        klass              
      end
    end.compact
    @_contentclasses -= do_not_include
    
    Rails.logger.debug("Content constants: #{@_contentclasses.map{|c| c.to_s}.inspect}")    
    @_contentclasses
  end
    
  # Does this implementations have a Settings class?
  def has_settings?
    "Setting".constantize
    true
  rescue NameError
    false
  end
  memoize :has_settings?
  
  # The settings class for this implementation
  def settings
    "Setting".constantize if self.has_settings?
  end
  
  # Retrieve a content_class from the Implementation namespace by type
  # type can be a plural or a singular.
  def content_class(type)
    type_class_name = type.to_s.singularize.camelcase
    return if type_class_name.blank?
    content_class = type_class_name.constantize
    content_class if content_class.content? && !content_class.abstract_class
  rescue StandardError => e
    Rails.logger.warn("Failure while trying to get #{type_class_name} : #{e} #{e.backtrace.join("\n\t")}")
    nil
  end
  
end    

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
westarete-skylinecms-3.0.8.20100329 lib/skyline/content/implementation.rb
westarete-skylinecms-3.0.8.20100330 lib/skyline/content/implementation.rb