Module: Moped::PromiscuousQueryWrapper::PromiscuousHelpers
- Included in:
- PromiscuousReadOperation, PromiscuousWriteOperation
- Defined in:
- lib/promiscuous/publisher/operation/mongoid.rb
Instance Method Summary collapse
Instance Method Details
#collection_name ⇒ Object
77 78 79 |
# File 'lib/promiscuous/publisher/operation/mongoid.rb', line 77 def collection_name @collection_name ||= @query.collection.is_a?(String) ? @query.collection : @query.collection.name end |
#get_selector_instance ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/promiscuous/publisher/operation/mongoid.rb', line 85 def get_selector_instance selector = @query.operation.selector["$query"] || @query.operation.selector # TODO use the original instance for an update/delete, that would be # an even better hint. # We only support == selectors, no $in, or $gt. @selector = selector.select { |k,v| k.to_s =~ /^[^$]/ && !v.is_a?(Hash) } # @instance is not really a proper instance of a model, it's just a # convenient representation of a selector as explain in base.rb, # which explain why we don't want any constructor to be called. # Note that this optimistic mechanism also works with writes because # the instance gets reloaded once the lock is taken. If the # dependencies were incorrect, the locks will be released and # reacquired appropriately. model.allocate.tap { |doc| doc.instance_variable_set(:@attributes, @selector) } end |
#model ⇒ Object
81 82 83 |
# File 'lib/promiscuous/publisher/operation/mongoid.rb', line 81 def model @model ||= Promiscuous::Publisher::Model::Mongoid.collection_mapping[collection_name] end |