has_constant 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.9
data/has_constant.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_constant}
8
- s.version = "0.2.8"
8
+ s.version = "0.2.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mattbeedle"]
@@ -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: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 8
10
- version: 0.2.8
9
+ - 9
10
+ version: 0.2.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - mattbeedle