mongoid_adjust 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -28
- data/VERSION +1 -1
- data/lib/mongoid_adjust.rb +17 -37
- data/mongoid_adjust.gemspec +54 -0
- metadata +49 -83
- data/.gitignore +0 -21
data/Rakefile
CHANGED
@@ -10,10 +10,10 @@ begin
|
|
10
10
|
gem.email = "kmandrup@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/kristianmandrup/mongoid_adjust"
|
12
12
|
gem.authors = ["Kristian Mandrup"]
|
13
|
-
gem.add_dependency("mongoid", ">= 2.0.
|
14
|
-
gem.add_dependency("bson", ">= 1.
|
13
|
+
gem.add_dependency("mongoid", ">= 2.0.1")
|
14
|
+
gem.add_dependency("bson", ">= 1.2")
|
15
15
|
|
16
|
-
gem.add_development_dependency "rspec", ">= 2.0.
|
16
|
+
gem.add_development_dependency "rspec", ">= 2.0.1"
|
17
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
18
|
end
|
19
19
|
Jeweler::GemcutterTasks.new
|
@@ -21,28 +21,4 @@ rescue LoadError
|
|
21
21
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
-
# spec.libs << 'lib' << 'spec'
|
27
|
-
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
-
# spec.libs << 'lib' << 'spec'
|
32
|
-
# spec.pattern = 'spec/**/*_spec.rb'
|
33
|
-
# spec.rcov = true
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# task :spec => :check_dependencies
|
37
|
-
#
|
38
|
-
# task :default => :spec
|
39
|
-
#
|
40
|
-
# require 'rake/rdoctask'
|
41
|
-
# Rake::RDocTask.new do |rdoc|
|
42
|
-
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
-
#
|
44
|
-
# rdoc.rdoc_dir = 'rdoc'
|
45
|
-
# rdoc.title = "mongoid_adjust #{version}"
|
46
|
-
# rdoc.rdoc_files.include('README*')
|
47
|
-
# rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
-
# end
|
24
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/mongoid_adjust.rb
CHANGED
@@ -9,7 +9,7 @@ module Mongoid::Extensions::Array
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
self
|
12
|
-
end
|
12
|
+
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -17,66 +17,46 @@ module Mongoid
|
|
17
17
|
class Criteria
|
18
18
|
def adjust!(attrs = {})
|
19
19
|
to_a.adjust!(attrs)
|
20
|
-
end
|
20
|
+
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
|
-
module Mongoid::Document
|
23
|
+
|
24
|
+
module Mongoid::Document
|
25
25
|
|
26
26
|
def has_key? key
|
27
27
|
@attributes[key.to_s] || respond_to?("#{key}=")
|
28
28
|
end
|
29
|
-
|
30
|
-
def adjust!(attrs = {})
|
29
|
+
|
30
|
+
def adjust!(attrs = {})
|
31
31
|
(attrs || {}).each_pair do |key, value|
|
32
32
|
next if !has_key? key # only add to properties already present!
|
33
33
|
adjust_by_proc!(key, value) if value.kind_of?(Proc)
|
34
34
|
adjust_by_symbol!(key, value) if value.kind_of?(Symbol) || value.kind_of?(String)
|
35
|
-
adjust_by_number!(key, value) if value.kind_of?(Numeric) # only add integer values
|
35
|
+
adjust_by_number!(key, value) if value.kind_of?(Numeric) # only add integer values
|
36
36
|
end
|
37
37
|
self
|
38
|
-
end
|
38
|
+
end
|
39
39
|
|
40
|
-
private
|
40
|
+
private
|
41
41
|
|
42
42
|
def adjust_by_proc! key, proc
|
43
|
-
|
44
|
-
|
45
|
-
@attributes[key.to_s] = proc.call(current_val)
|
46
|
-
else
|
47
|
-
current_val = send("#{key}")
|
48
|
-
send("#{key}=", proc.call(current_val))
|
49
|
-
end
|
43
|
+
current_val = @attributes[key.to_s]
|
44
|
+
self.update_attributes key.to_s => proc.call(current_val)
|
50
45
|
end
|
51
46
|
|
52
47
|
def adjust_by_symbol! key, name
|
53
48
|
method = name.to_sym
|
54
|
-
|
55
|
-
|
56
|
-
@attributes[key.to_s] = current_val.send(method)
|
57
|
-
else
|
58
|
-
current_val = send("#{key}")
|
59
|
-
send("#{key}=", current_val.send(method))
|
60
|
-
end
|
49
|
+
current_val = @attributes[key.to_s]
|
50
|
+
self.update_attributes key.to_s => current_val.send(method)
|
61
51
|
end
|
62
52
|
|
63
|
-
|
64
53
|
def adjust_by_number! key, value
|
65
|
-
|
66
|
-
current_val = @attributes[key.to_s] || 0
|
54
|
+
current_val = @attributes[key.to_s] || 0
|
67
55
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
else
|
72
|
-
current_val = send("#{key}") || 0
|
73
|
-
|
74
|
-
if current_val.kind_of? Numeric
|
75
|
-
send("#{key}=", current_val + value)
|
76
|
-
end
|
77
|
-
end
|
56
|
+
if current_val.kind_of? Numeric
|
57
|
+
self.update_attributes key.to_s => current_val + value
|
58
|
+
end
|
78
59
|
end
|
79
|
-
|
80
60
|
end
|
81
61
|
|
82
62
|
class Array
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "mongoid_adjust"
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = "2011-09-30"
|
13
|
+
s.description = "Add simple adjust! method to Mongoid."
|
14
|
+
s.email = "kmandrup@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/mongoid_adjust.rb",
|
26
|
+
"mongoid_adjust.gemspec",
|
27
|
+
"spec/.rspec",
|
28
|
+
"spec/mongoid_adjust_spec.rb",
|
29
|
+
"spec/spec_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = "http://github.com/kristianmandrup/mongoid_adjust"
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = "1.8.10"
|
34
|
+
s.summary = "Add simple adjust! method to Mongoid"
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_runtime_dependency(%q<mongoid>, [">= 2.0.1"])
|
41
|
+
s.add_runtime_dependency(%q<bson>, [">= 1.2"])
|
42
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<mongoid>, [">= 2.0.1"])
|
45
|
+
s.add_dependency(%q<bson>, [">= 1.2"])
|
46
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
47
|
+
end
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<mongoid>, [">= 2.0.1"])
|
50
|
+
s.add_dependency(%q<bson>, [">= 1.2"])
|
51
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
metadata
CHANGED
@@ -1,123 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_adjust
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Kristian Mandrup
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-09-30 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: mongoid
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2154576260 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 2
|
30
|
-
- 0
|
31
|
-
- 0
|
32
|
-
- beta
|
33
|
-
- 14
|
34
|
-
version: 2.0.0.beta.14
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.1
|
35
22
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: bson
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: *2154576260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bson
|
27
|
+
requirement: &2154575740 !ruby/object:Gem::Requirement
|
41
28
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
- 1
|
47
|
-
- 0
|
48
|
-
- 3
|
49
|
-
version: 1.0.3
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.2'
|
50
33
|
type: :runtime
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: rspec
|
54
34
|
prerelease: false
|
55
|
-
|
35
|
+
version_requirements: *2154575740
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2154575200 !ruby/object:Gem::Requirement
|
56
39
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
- 2
|
62
|
-
- 0
|
63
|
-
- 0
|
64
|
-
- beta
|
65
|
-
- 15
|
66
|
-
version: 2.0.0.beta.15
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.0.1
|
67
44
|
type: :development
|
68
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2154575200
|
69
47
|
description: Add simple adjust! method to Mongoid.
|
70
48
|
email: kmandrup@gmail.com
|
71
49
|
executables: []
|
72
|
-
|
73
50
|
extensions: []
|
74
|
-
|
75
|
-
extra_rdoc_files:
|
51
|
+
extra_rdoc_files:
|
76
52
|
- LICENSE
|
77
53
|
- README.markdown
|
78
|
-
files:
|
54
|
+
files:
|
79
55
|
- .document
|
80
|
-
- .gitignore
|
81
56
|
- LICENSE
|
57
|
+
- README.markdown
|
82
58
|
- Rakefile
|
83
59
|
- VERSION
|
84
60
|
- lib/mongoid_adjust.rb
|
61
|
+
- mongoid_adjust.gemspec
|
85
62
|
- spec/.rspec
|
86
63
|
- spec/mongoid_adjust_spec.rb
|
87
64
|
- spec/spec_helper.rb
|
88
|
-
- README.markdown
|
89
|
-
has_rdoc: true
|
90
65
|
homepage: http://github.com/kristianmandrup/mongoid_adjust
|
91
66
|
licenses: []
|
92
|
-
|
93
67
|
post_install_message:
|
94
|
-
rdoc_options:
|
95
|
-
|
96
|
-
require_paths:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
97
70
|
- lib
|
98
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
72
|
none: false
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
104
|
-
|
105
|
-
version: "0"
|
106
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
78
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
- 0
|
113
|
-
version: "0"
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
114
83
|
requirements: []
|
115
|
-
|
116
84
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
85
|
+
rubygems_version: 1.8.10
|
118
86
|
signing_key:
|
119
87
|
specification_version: 3
|
120
88
|
summary: Add simple adjust! method to Mongoid
|
121
|
-
test_files:
|
122
|
-
- spec/mongoid_adjust_spec.rb
|
123
|
-
- spec/spec_helper.rb
|
89
|
+
test_files: []
|