File: mongoid.rb

package info (click to toggle)
ruby-stringex 2.8.5-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,232 kB
  • sloc: ruby: 3,745; makefile: 5
file content (37 lines) | stat: -rw-r--r-- 984 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Stringex
  module ActsAsUrl
    module Adapter
      class Mongoid < Base
        def self.load
          ensure_loadable
          orm_class.send :extend, Stringex::ActsAsUrl::ActsAsUrlClassMethods
        end

      private

        def add_new_record_url_owner_conditions
          return if instance.new_record?
          @url_owner_conditions.merge! id: {'$ne' => instance.id}
        end

        def add_scoped_url_owner_conditions
          [settings.scope_for_url].flatten.compact.each do |scope|
            @url_owner_conditions.merge! scope => instance.send(scope)
          end
        end

        def get_base_url_owner_conditions
          @url_owner_conditions = {settings.url_attribute => /^#{Regexp.escape(base_url)}/}
        end

        def klass_previous_instances(&block)
          klass.all(settings.url_attribute => [nil]).to_a.each(&block)
        end

        def self.orm_class
          ::Mongoid::Document
        end
      end
    end
  end
end