lib/mongoid-dsl/monkey.rb in mongoid-dsl-1.3.0 vs lib/mongoid-dsl/monkey.rb in mongoid-dsl-1.3.1

- old
+ new

@@ -328,13 +328,13 @@ # path trim begin deep_level = (full_path.count) || 0 - chains= full_path + chains = full_path - if !full_path.empty? && !full_path.nil? + if !full_path.nil? && !full_path.empty? full_path= full_path.join('.')+'.' else full_path= String.new end @@ -465,26 +465,10 @@ end end - # TODO find out how to add elements to a criteria obj - # # convert to mongid criteria - # begin - # - # mongoid_crit= Mongoid::Criteria.new(self) - # - # puts mongoid_crit.methods - Object.methods - # - # - # mongoid_crit.add_to_set return_data[0] - # - # return mongoid_crit - # - # rescue Exception - # end - return return_data end def _where(*args) @@ -493,33 +477,16 @@ def _all(*args) self.__query_wrapper(['all',{:arguments? => false}],*args) end def _find(target_id) - - # pre validation - begin - if target_id.class != Moped::BSON::ObjectId && target_id.class != String - raise ArgumentError, "id parameter must be id or ObjectId" - end - end - - # Do the Gangnam style - begin - return_doc = self._where( '_id' => target_id )[0] - end - - return return_doc + return self._where( + '_id' => Moped::BSON::ObjectId.from_string(target_id.to_s) + )[0] end def _find_by(*args) - - # Do the Gangnam style - begin - return_array = self._where(*args).first - end - - return return_array + return self._where(*args).first end #> [:none,:self,:one,:many] def relation_to?(klass) raise(ArgumentError,"obj must be class: #{klass}") unless klass <= Class @@ -602,10 +569,10 @@ when ![ ::Symbol, ::String].select{ |klass|self.class <= klass }.empty? Mongoid.models.each do |model_name| mongoid_model_name= model_name.mongoid_name - unless [mongoid_model_name,mongoid_model_name+'s'].select{|mn| self.to_s == mn }.empty? + if [mongoid_model_name,mongoid_model_name+'s'].any?{|mn| self.to_s == mn } return model_name.to_s.constantize end end return self.to_s.split('::').last.underscore \ No newline at end of file