mongoid-unscoped-relations 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/mongoid-unscoped-relations.rb +4 -0
- data/lib/mongoid/unscoped_belongs_to.rb +30 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f680be9151b1502374f4f506cdc9360031946be9
|
4
|
+
data.tar.gz: 724c8f634923cf5bbe0b4b17c204aded652694c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bef3182bab85bca0067967a33144e86c4a191406ed6f7401f83d249f90e2d594cfbf4bf76b72ea3d375a3a094b12aae5179d3f74d87742fa4bd66ddc3f89c1bf
|
7
|
+
data.tar.gz: 7342581ada81380d7aa2794f91fa7da6429a35318d7aa76b13cf50d2fc6914be5544a665809906493b43281b2e349fc4b4e8106c26ddd868157019373c50152d
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module UnscopedBelongsTo
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def unscoped_belongs_to(field, args = {})
|
7
|
+
belongs_to field, args
|
8
|
+
|
9
|
+
define_method field do
|
10
|
+
field_id = send("#{field}_id")
|
11
|
+
field_name = "@#{field}"
|
12
|
+
return nil if field_id.nil?
|
13
|
+
|
14
|
+
cur_value = instance_variable_get field_name
|
15
|
+
return cur_value if cur_value.present?
|
16
|
+
|
17
|
+
clazz = Object.const_get self.relations[field.to_s].class_name
|
18
|
+
cur_value = clazz.unscoped.find field_id
|
19
|
+
return instance_variable_set field_name, cur_value
|
20
|
+
end
|
21
|
+
|
22
|
+
mongoid_setter = instance_method("#{field}=")
|
23
|
+
define_method "#{field}=" do |field_value|
|
24
|
+
instance_variable_set "@#{field}", field_value
|
25
|
+
mongoid_setter.bind(self).call(field_value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid-unscoped-relations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Léo Unbekandt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mongoid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
description: Extension to mongoid to define relationships which are fetched unscoped
|
42
|
+
email: leo@scalingo.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/mongoid-unscoped-relations.rb
|
48
|
+
- lib/mongoid/unscoped_belongs_to.rb
|
49
|
+
homepage: http://github.com/Scalingo/mongoid-unscoped-relations
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.6.13
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Mongoid extension for unscoped relations
|
73
|
+
test_files: []
|