Module: Redmine::SubclassFactory::ClassMethods

Defined in:
lib/redmine/subclass_factory.rb

Instance Method Summary collapse

Instance Method Details

#get_subclass(class_name) ⇒ Object



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

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

#new_subclass_instance(class_name, *args) ⇒ Object

Returns an instance of the given subclass name



41
42
43
44
45
46
# File 'lib/redmine/subclass_factory.rb', line 41

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