Module: Redmine::SubclassFactory::ClassMethods

Defined in:
lib/redmine/subclass_factory.rb

Instance Method Summary collapse

Instance Method Details

#get_subclass(class_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/redmine/subclass_factory.rb', line 25

def get_subclass(class_name)
  klass = nil
  begin
    klass = class_name.to_s.classify.constantize
  rescue
    # invalid class name
  end
  unless subclasses.include? klass
    klass = nil
  end
  klass
end

#new_subclass_instance(class_name, *args) ⇒ Object

Returns an instance of the given subclass name



39
40
41
42
43
44
# File 'lib/redmine/subclass_factory.rb', line 39

def new_subclass_instance(class_name, *args)
  klass = get_subclass(class_name)
  if klass
    klass.new(*args)
  end
end