has_constant 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -10,6 +10,10 @@ group :test do
10
10
  gem 'bson'
11
11
  gem 'bson_ext'
12
12
  gem 'mocha'
13
+
14
+ gem 'dm-core'
15
+ gem 'dm-postgres-adapter'
16
+ gem 'dm-migrations'
13
17
  end
14
18
 
15
19
  group :development do
data/Gemfile.lock CHANGED
@@ -1,30 +1,46 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.0.3)
5
- activesupport (= 3.0.3)
4
+ activemodel (3.0.4)
5
+ activesupport (= 3.0.4)
6
6
  builder (~> 2.1.2)
7
7
  i18n (~> 0.4)
8
- activerecord (3.0.3)
9
- activemodel (= 3.0.3)
10
- activesupport (= 3.0.3)
8
+ activerecord (3.0.4)
9
+ activemodel (= 3.0.4)
10
+ activesupport (= 3.0.4)
11
11
  arel (~> 2.0.2)
12
12
  tzinfo (~> 0.3.23)
13
- activesupport (3.0.3)
14
- arel (2.0.6)
15
- bson (1.1.5)
16
- bson_ext (1.1.5)
13
+ activesupport (3.0.4)
14
+ addressable (2.2.4)
15
+ arel (2.0.8)
16
+ bson (1.2.2)
17
+ bson_ext (1.2.2)
17
18
  builder (2.1.2)
19
+ data_objects (0.10.3)
20
+ addressable (~> 2.1)
21
+ dm-core (1.0.2)
22
+ addressable (~> 2.2)
23
+ extlib (~> 0.9.15)
24
+ dm-do-adapter (1.0.2)
25
+ data_objects (~> 0.10.2)
26
+ dm-core (~> 1.0.2)
27
+ dm-migrations (1.0.2)
28
+ dm-core (~> 1.0.2)
29
+ dm-postgres-adapter (1.0.2)
30
+ dm-do-adapter (~> 1.0.2)
31
+ do_postgres (~> 0.10.2)
32
+ do_postgres (0.10.3)
33
+ data_objects (= 0.10.3)
34
+ extlib (0.9.15)
18
35
  git (1.2.5)
19
36
  i18n (0.5.0)
20
- jeweler (1.5.1)
37
+ jeweler (1.5.2)
21
38
  bundler (~> 1.0.0)
22
39
  git (>= 1.2.5)
23
40
  rake
24
- mocha (0.9.11)
25
- rake
26
- mongo (1.1.5)
27
- bson (>= 1.1.5)
41
+ mocha (0.9.12)
42
+ mongo (1.2.2)
43
+ bson (>= 1.2.2)
28
44
  mongoid (2.0.0.beta.20)
29
45
  activemodel (~> 3.0)
30
46
  mongo (~> 1.1)
@@ -32,8 +48,10 @@ GEM
32
48
  will_paginate (~> 3.0.pre)
33
49
  rake (0.8.7)
34
50
  shoulda (2.11.3)
35
- sqlite3-ruby (1.3.2)
36
- tzinfo (0.3.23)
51
+ sqlite3 (1.3.3)
52
+ sqlite3-ruby (1.3.3)
53
+ sqlite3 (>= 1.3.3)
54
+ tzinfo (0.3.24)
37
55
  will_paginate (3.0.pre2)
38
56
 
39
57
  PLATFORMS
@@ -44,6 +62,9 @@ DEPENDENCIES
44
62
  activesupport
45
63
  bson
46
64
  bson_ext
65
+ dm-core
66
+ dm-migrations
67
+ dm-postgres-adapter
47
68
  jeweler
48
69
  mocha
49
70
  mongoid (= 2.0.0.beta.20)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.4.9
data/has_constant.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_constant}
8
- s.version = "0.4.8"
8
+ s.version = "0.4.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"]
12
- s.date = %q{2011-02-07}
12
+ s.date = %q{2011-02-18}
13
13
  s.description = %q{Allows certain fields to be limited to a set of values}
14
14
  s.email = %q{mattbeedle@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -9,9 +9,12 @@ module HasConstant
9
9
 
10
10
  singular = (options[:accessor] || name.to_s.singularize).to_s
11
11
 
12
- # Add the getter method. This returns the string representation of the stored value
12
+ # Add the getter method. This returns the string representation of
13
+ # the stored value
13
14
  define_method(singular) do
14
- self.class.send(name)[read_attribute(singular).to_i] if read_attribute(singular)
15
+ if read_attribute(singular)
16
+ self.class.send(name)[read_attribute(singular).to_i]
17
+ end
15
18
  end
16
19
 
17
20
  define_method("#{singular}=") do |val|
@@ -23,14 +26,32 @@ module HasConstant
23
26
  end
24
27
 
25
28
  class_eval do
26
- named_scope :by_constant, lambda { |constant,value| { :conditions =>
27
- { constant.to_sym => eval("#{self.to_s}.#{constant.pluralize}.index(value)") } } }
28
- named_scope "#{singular}_is".to_sym, lambda { |*values| { :conditions =>
29
- { singular.to_sym => indexes_for(name, values) }
30
- } }
31
- named_scope "#{singular}_is_not".to_sym, lambda { |*values| { :conditions =>
32
- ["#{singular} NOT IN (?)", indexes_for(name, values)]
33
- } }
29
+ if respond_to?(:scope)
30
+ scope :by_constant, lambda { |constant,value| { :conditions =>
31
+ { constant.to_sym =>
32
+ eval("#{self.to_s}.#{constant.pluralize}.index(value)") } } }
33
+
34
+ scope "#{singular}_is".to_sym, lambda { |*values| { :conditions =>
35
+ { singular.to_sym => indexes_for(name, values) }
36
+ } }
37
+
38
+ scope "#{singular}_is_not".to_sym, lambda { |*values| {
39
+ :conditions => ["#{singular} NOT IN (?)",
40
+ indexes_for(name, values)] } }
41
+ else
42
+ named_scope :by_constant, lambda { |constant,value| {
43
+ :conditions =>
44
+ { constant.to_sym =>
45
+ eval("#{self.to_s}.#{constant.pluralize}.index(value)") } } }
46
+
47
+ named_scope "#{singular}_is".to_sym, lambda { |*values| {
48
+ :conditions => { singular.to_sym => indexes_for(name, values) }
49
+ } }
50
+
51
+ named_scope "#{singular}_is_not".to_sym, lambda { |*values| {
52
+ :conditions => ["#{singular} NOT IN (?)",
53
+ indexes_for(name, values)] } }
54
+ end
34
55
  end
35
56
  end
36
57
 
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 8
10
- version: 0.4.8
9
+ - 9
10
+ version: 0.4.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - mattbeedle
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-07 00:00:00 +01:00
18
+ date: 2011-02-18 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency