Module: Mongoid::Miscellaneous
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongoid_misc/miscellaneous.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #dom_id ⇒ Object
- #exist? ⇒ Boolean (also: #exists?)
- #first!(*a) ⇒ Object
- #set_protected_attributes(attribute_names, attributes) ⇒ Object
- #t(*a) ⇒ Object
- #upsert!(*args) ⇒ Object
Instance Method Details
#dom_id ⇒ Object
13 14 15 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 13 def dom_id new_record? ? "new_#{self.class.name.underscore}" : to_param end |
#exist? ⇒ Boolean Also known as: exists?
8 9 10 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 8 def exist? self.class.where(_id: id).count > 0 end |
#first!(*a) ⇒ Object
17 18 19 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 17 def first! *a super || raise(Mongoid::Errors::DocumentNotFound.new(self, a)) end |
#set_protected_attributes(attribute_names, attributes) ⇒ Object
21 22 23 24 25 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 21 def set_protected_attributes attribute_names, attributes attribute_names.each do |name| send "#{name}=", attributes[name] if attributes.include? name end end |
#t(*a) ⇒ Object
27 28 29 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 27 def t *a I18n.t *a end |
#upsert!(*args) ⇒ Object
4 5 6 |
# File 'lib/mongoid_misc/miscellaneous.rb', line 4 def upsert! *args self.class.upsert!({id: id}, *args) end |