Sha256: 8bb611d8425be84ea34103f29e64a1de4ced584d175788eb57f4d25787a55bff

Contents?: true

Size: 593 Bytes

Versions: 15

Compression:

Stored size: 593 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_name)
    load_class(obj_class_name) || @fallback_class
  end

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

  private

  def load_class(obj_class_name)
    klass = obj_class_name.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

15 entries across 15 versions & 1 rubygems

Version Path
scrivito_sdk-0.50.1 lib/scrivito/type_computer.rb
scrivito_sdk-0.50.0 lib/scrivito/type_computer.rb
scrivito_sdk-0.50.0.rc2 lib/scrivito/type_computer.rb
scrivito_sdk-0.50.0.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-0.42.1 lib/scrivito/type_computer.rb
scrivito_sdk-0.42.1.rc3 lib/scrivito/type_computer.rb
scrivito_sdk-0.42.1.rc2 lib/scrivito/type_computer.rb
scrivito_sdk-0.42.1.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-0.42.0 lib/scrivito/type_computer.rb
scrivito_sdk-0.41.1 lib/scrivito/type_computer.rb
scrivito_sdk-0.41.0 lib/scrivito/type_computer.rb
scrivito_sdk-0.41.0.rc2 lib/scrivito/type_computer.rb
scrivito_sdk-0.41.0.rc1 lib/scrivito/type_computer.rb
scrivito_sdk-0.40.0 lib/scrivito/type_computer.rb
scrivito_sdk-0.40.0.rc2 lib/scrivito/type_computer.rb