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.5.5 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.1 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.1.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.5.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.4.3 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.4 lib/scrivito/type_computer.rb
scrivito_sdk-1.7.0.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.0 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.0.rc5 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.4.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.0.rc4 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.0.rc3 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.3 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.0.rc2 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.3.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.6.0.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.2 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.2.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.1 lib/scrivito/type_computer.rb
scrivito_sdk-1.5.1.rc2 lib/scrivito/type_computer.rb