has_constant 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/has_constant.gemspec +1 -1
- data/lib/has_constant/orm/mongoid.rb +12 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.9
|
data/has_constant.gemspec
CHANGED
@@ -41,14 +41,22 @@ module HasConstant
|
|
41
41
|
write_attribute singular.to_sym, val
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
(class << self; self; end).instance_eval do
|
46
|
+
define_method "#{singular}_is".to_sym do |values|
|
47
|
+
values = values.lines.to_a if values.respond_to?(:lines)
|
48
|
+
where(singular.to_sym => { '$in' => values.map { |v| self.send(name.to_sym).index(v) } })
|
49
|
+
end
|
50
|
+
|
51
|
+
define_method "#{singular}_is_not".to_sym do |values|
|
52
|
+
values = values.lines.to_a if values.respond_to?(:lines)
|
53
|
+
where(singular.to_sym => { '$nin' => values.map { |v| self.send(name.to_sym).index(v) } })
|
54
|
+
end
|
55
|
+
end
|
44
56
|
|
45
57
|
class_eval do
|
46
58
|
named_scope :by_constant, lambda { |constant,value| { :where =>
|
47
59
|
{ constant.to_sym => eval("#{self.to_s}.#{constant.pluralize}.index(value)") } } }
|
48
|
-
named_scope "#{singular}_is".to_sym, lambda { |values| { :where =>
|
49
|
-
{ singular.to_sym => { '$in' => values.to_a.map { |v| self.send(name.to_sym).index(v) } } } } }
|
50
|
-
named_scope "#{singular}_is_not".to_sym, lambda { |values| { :where =>
|
51
|
-
{ singular.to_sym => { '$nin' => values.to_a.map { |v| self.send(name.to_sym).index(v) } } } } }
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_constant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 9
|
10
|
+
version: 0.2.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mattbeedle
|