Module: Mongoid::DSL::CoreExt::Include

Defined in:
lib/mongoid-dsl/monkey.rb

Instance Method Summary collapse

Instance Method Details

#convert_model_nameObject Also known as: mongoise_name, mongoize_name, mongoid_name, mongoid_name_convert

convert mongoid name



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/mongoid-dsl/monkey.rb', line 582

def convert_model_name

  unless self.class <= Class || self.class <= String || self.class <= Symbol || self.class <= NilClass
    raise ArgumentError, "invalid input, must be Class or String: => #{self.class} (#{self})"
  end

  if self.class <= NilClass
    return nil
  end

  case self.class.to_s

    when "Class"
      return self.to_s.split('::').last.underscore

    when "String","Symbol"
      Mongoid.models.each do |one_model_name|
        if  self.to_s == one_model_name.to_s.split('::').last.underscore || \
            self.to_s == one_model_name.to_s.split('::').last.underscore+('s')

          return one_model_name.to_s.constantize

        end
      end

      return self.to_s.split('::').last.underscore


  end

  return nil
end