Sha256: cc0a18a5933a2293b6120863112d84b2aaf9cc9ec1332e137ab89f6bacd7a1e3

Contents?: true

Size: 755 Bytes

Versions: 65

Compression:

Stored size: 755 Bytes

Contents

module Scrivito

class TypeComputer
  def initialize(base_class, fallback_class)
    @base_class, @fallback_class = base_class, fallback_class
  end

  def compute_type(obj_class)
   load_class(obj_class) || @fallback_class
  end

  def compute_type_without_fallback(obj_class_name)
    if obj_class = load_class(obj_class_name)
      obj_class
    else
      raise ObjClassNotFound, obj_class_name
    end
  end

  def special_class?(klass)
    klass == @base_class || klass == @fallback_class
  end

  private

  def load_class(obj_class)
    klass = obj_class.constantize
    klass if inherits_from_base?(klass)
  rescue NameError
  end

  def inherits_from_base?(klass)
    klass.ancestors.include?(@base_class) && klass != @base_class
  end
end

end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
scrivito_sdk-1.11.0 app/cms/scrivito/type_computer.rb
scrivito_sdk-1.11.0.rc1 app/cms/scrivito/type_computer.rb
scrivito_sdk-1.10.0 app/cms/scrivito/type_computer.rb
scrivito_sdk-1.10.0.rc5 app/cms/scrivito/type_computer.rb
scrivito_sdk-1.10.0.rc4 app/cms/scrivito/type_computer.rb
scrivito_sdk-1.10.0.rc3 app/cms/scrivito/type_computer.rb
scrivito_sdk-1.10.0.rc2 lib/scrivito/type_computer.rb
scrivito_sdk-1.10.0.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.9.1 lib/scrivito/type_computer.rb
scrivito_sdk-1.9.1.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.9.0 lib/scrivito/type_computer.rb
scrivito_sdk-1.9.0.rc2 lib/scrivito/type_computer.rb
scrivito_sdk-1.9.0.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.8.1 lib/scrivito/type_computer.rb
scrivito_sdk-1.8.1.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.8.0 lib/scrivito/type_computer.rb
scrivito_sdk-1.8.0.rc2 lib/scrivito/type_computer.rb
scrivito_sdk-1.8.0.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.7.0 lib/scrivito/type_computer.rb
scrivito_sdk-1.7.0.rc2 lib/scrivito/type_computer.rb