dm-adjust 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +3 -0
- data/README.txt +4 -4
- data/Rakefile +18 -46
- data/TODO +0 -6
- data/lib/dm-adjust.rb +2 -1
- data/lib/dm-adjust/collection.rb +11 -5
- data/lib/dm-adjust/model.rb +6 -2
- data/lib/dm-adjust/resource.rb +23 -0
- data/lib/dm-adjust/version.rb +2 -4
- data/spec/integration/adjust_spec.rb +15 -6
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +4 -7
- data/tasks/install.rb +13 -0
- data/tasks/spec.rb +25 -0
- metadata +8 -14
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -9,7 +9,10 @@ lib/dm-adjust/adapters/data_objects_adapter.rb
|
|
9
9
|
lib/dm-adjust/collection.rb
|
10
10
|
lib/dm-adjust/model.rb
|
11
11
|
lib/dm-adjust/repository.rb
|
12
|
+
lib/dm-adjust/resource.rb
|
12
13
|
lib/dm-adjust/version.rb
|
13
14
|
spec/integration/adjust_spec.rb
|
14
15
|
spec/spec.opts
|
15
16
|
spec/spec_helper.rb
|
17
|
+
tasks/install.rb
|
18
|
+
tasks/spec.rb
|
data/README.txt
CHANGED
@@ -5,8 +5,8 @@ DataMapper plugin providing methods to increment and decrement properties
|
|
5
5
|
|
6
6
|
It provides the following function (for collections and resources):
|
7
7
|
|
8
|
-
== adjust
|
8
|
+
== adjust!
|
9
9
|
|
10
|
-
Person.adjust(:salary => 1000) # increases the salary of all people with 1000.
|
11
|
-
Person.all(:age.gte => 40).adjust(:salary => 2000) # increase salary of them oldies.
|
12
|
-
|
10
|
+
Person.adjust!(:salary => 1000) # increases the salary of all people with 1000.
|
11
|
+
Person.all(:age.gte => 40).adjust!(:salary => 2000) # increase salary of them oldies.
|
12
|
+
@child.adjust!(:allowance => -100) # less money for candy and concerts
|
data/Rakefile
CHANGED
@@ -1,53 +1,25 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'spec'
|
3
|
-
require 'spec/rake/spectask'
|
4
1
|
require 'pathname'
|
2
|
+
require 'rubygems'
|
5
3
|
|
6
|
-
ROOT
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
EMAIL = "sindre [a] identu [d] no"
|
11
|
-
GEM_NAME = "dm-adjust"
|
12
|
-
GEM_VERSION = DataMapper::More::Adjust::VERSION
|
13
|
-
GEM_DEPENDENCIES = [["dm-core", GEM_VERSION]]
|
14
|
-
GEM_CLEAN = ["log", "pkg"]
|
15
|
-
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO ] }
|
16
|
-
|
17
|
-
PROJECT_NAME = "datamapper"
|
18
|
-
PROJECT_URL = "http://github.com/sam/dm-more/tree/master/dm-adjust"
|
19
|
-
PROJECT_DESCRIPTION = PROJECT_SUMMARY = "DataMapper plugin providing methods to increment and decrement properties"
|
20
|
-
|
21
|
-
require ROOT.parent + 'tasks/hoe'
|
22
|
-
|
23
|
-
task :default => [ :spec ]
|
24
|
-
|
25
|
-
WIN32 = (RUBY_PLATFORM =~ /win32|mingw|cygwin/) rescue nil
|
26
|
-
SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
|
4
|
+
ROOT = Pathname(__FILE__).dirname.expand_path
|
5
|
+
JRUBY = RUBY_PLATFORM =~ /java/
|
6
|
+
WINDOWS = Gem.win_platform?
|
7
|
+
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
|
27
8
|
|
28
|
-
|
29
|
-
task :install => [ :package ] do
|
30
|
-
sh "#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources", :verbose => false
|
31
|
-
end
|
9
|
+
require ROOT + 'lib/dm-adjust/version'
|
32
10
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
11
|
+
AUTHOR = 'Sindre Aarsaether'
|
12
|
+
EMAIL = 'sindre [a] identu [d] no'
|
13
|
+
GEM_NAME = 'dm-adjust'
|
14
|
+
GEM_VERSION = DataMapper::Adjust::VERSION
|
15
|
+
GEM_DEPENDENCIES = [['dm-core', "~>#{GEM_VERSION}"]]
|
16
|
+
GEM_CLEAN = %w[ log pkg coverage ]
|
17
|
+
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] }
|
39
18
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
|
19
|
+
PROJECT_NAME = 'datamapper'
|
20
|
+
PROJECT_URL = "http://github.com/sam/dm-more/tree/master/#{GEM_NAME}"
|
21
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin providing methods to increment and decrement properties'
|
44
22
|
|
45
|
-
|
46
|
-
|
47
|
-
t.rcov_opts << '--exclude' << 'spec'
|
48
|
-
t.rcov_opts << '--text-summary'
|
49
|
-
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
50
|
-
rescue Exception
|
51
|
-
# rcov not installed
|
52
|
-
end
|
23
|
+
[ ROOT, ROOT.parent ].each do |dir|
|
24
|
+
Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
|
53
25
|
end
|
data/TODO
CHANGED
data/lib/dm-adjust.rb
CHANGED
@@ -3,7 +3,7 @@ require 'pathname'
|
|
3
3
|
|
4
4
|
require Pathname(__FILE__).dirname + 'dm-adjust/version'
|
5
5
|
|
6
|
-
gem 'dm-core',
|
6
|
+
gem 'dm-core', '~>0.9.8'
|
7
7
|
require 'dm-core'
|
8
8
|
|
9
9
|
dir = Pathname(__FILE__).dirname.expand_path / 'dm-adjust'
|
@@ -11,4 +11,5 @@ dir = Pathname(__FILE__).dirname.expand_path / 'dm-adjust'
|
|
11
11
|
require dir / 'collection'
|
12
12
|
require dir / 'model'
|
13
13
|
require dir / 'repository'
|
14
|
+
require dir / 'resource'
|
14
15
|
require dir / 'adapters' / 'data_objects_adapter'
|
data/lib/dm-adjust/collection.rb
CHANGED
@@ -32,9 +32,16 @@ module DataMapper
|
|
32
32
|
# if the query contains a raw sql-string, we cannot (truly) know, and must load.
|
33
33
|
altered = query.conditions.detect{|c| adjust_attributes.include?(c[1]) || c[0] == :raw }
|
34
34
|
|
35
|
+
identity_map = repository.identity_map(model)
|
36
|
+
key_properties = model.key(repository.name)
|
37
|
+
|
35
38
|
if identity_map.any? && reload
|
36
|
-
reload_query =
|
37
|
-
|
39
|
+
reload_query = key_properties.zip(identity_map.keys.transpose).to_hash
|
40
|
+
|
41
|
+
if altered
|
42
|
+
keys = all(reload_query.merge(:fields => key_properties)).map { |r| r.key }
|
43
|
+
reload_query = model.key(repository.name).zip(keys.transpose).to_hash
|
44
|
+
end
|
38
45
|
end
|
39
46
|
|
40
47
|
repository.adjust(adjust_attributes,scoped_query)
|
@@ -53,8 +60,7 @@ module DataMapper
|
|
53
60
|
end
|
54
61
|
end if altered
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
end # adjust
|
63
|
+
true
|
64
|
+
end
|
59
65
|
end # Collection
|
60
66
|
end # DataMapper
|
data/lib/dm-adjust/model.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module DataMapper
|
2
2
|
module Model
|
3
3
|
|
4
|
+
def adjust(attributes = {}, reload = false)
|
5
|
+
raise NotImplementedError, 'adjust *with* validations has not be written yet, try adjust!'
|
6
|
+
end
|
7
|
+
|
4
8
|
##
|
5
9
|
# increment or decrement attributes on all objects in a resource
|
6
10
|
#
|
@@ -13,5 +17,5 @@ module DataMapper
|
|
13
17
|
def adjust!(attributes,reload=false)
|
14
18
|
all.adjust!(attributes,reload)
|
15
19
|
end
|
16
|
-
end
|
17
|
-
end
|
20
|
+
end # Model
|
21
|
+
end # DataMapper
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Resource
|
3
|
+
def adjust(attributes = {}, reload = false)
|
4
|
+
raise NotImplementedError, 'adjust *with* validations has not be written yet, try adjust!'
|
5
|
+
end
|
6
|
+
|
7
|
+
def adjust!(attributes = {}, reload = false)
|
8
|
+
return true if attributes.empty?
|
9
|
+
|
10
|
+
adjust_attributes = {}
|
11
|
+
|
12
|
+
model.properties(repository.name).slice(*attributes.keys).each do |property|
|
13
|
+
adjust_attributes[property] = attributes[property.name] if property
|
14
|
+
end
|
15
|
+
|
16
|
+
repository.adapter.adjust(adjust_attributes, to_query)
|
17
|
+
|
18
|
+
collection.reload(:fields => adjust_attributes.keys) if reload
|
19
|
+
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end # Resource
|
23
|
+
end # DataMapper
|
data/lib/dm-adjust/version.rb
CHANGED
@@ -13,7 +13,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
13
13
|
|
14
14
|
describe 'Adjust' do
|
15
15
|
|
16
|
-
before
|
16
|
+
before do
|
17
17
|
Person.auto_migrate!(:default)
|
18
18
|
Person.create(:name => 'George', :age => 15)
|
19
19
|
Person.create(:name => 'Puff', :age => 18)
|
@@ -23,11 +23,9 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
23
23
|
Person.create(:name => 'Amadeus',:age => 60)
|
24
24
|
end
|
25
25
|
|
26
|
-
describe '
|
26
|
+
describe 'Model#adjust!' do
|
27
27
|
it 'should adjust values' do
|
28
28
|
repository(:default) do
|
29
|
-
p = Person.get(1)
|
30
|
-
p.salary.should == 20000
|
31
29
|
Person.adjust!({:salary => 1000},true)
|
32
30
|
Person.all.each{|p| p.salary.should == 21000}
|
33
31
|
end
|
@@ -51,9 +49,20 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
51
49
|
|
52
50
|
it 'should load the query if conditions were adjusted' do
|
53
51
|
repository(:default) do |repos|
|
54
|
-
@specific = Person.all(:salary =>
|
52
|
+
@specific = Person.all(:salary => 20000)
|
55
53
|
@specific.adjust!({:salary => 5000},true)
|
56
|
-
@specific.length.should ==
|
54
|
+
@specific.length.should == 6
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'Resource#adjust' do
|
60
|
+
it 'should adjust the value' do
|
61
|
+
repository(:default) do |repos|
|
62
|
+
p = Person.get(1)
|
63
|
+
p.salary.should == 20000
|
64
|
+
p.adjust!({:salary => 1000},true)
|
65
|
+
p.salary.should == 21000
|
57
66
|
end
|
58
67
|
end
|
59
68
|
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
|
3
4
|
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/dm-adjust'
|
4
5
|
|
5
6
|
def load_driver(name, default_uri)
|
6
7
|
return false if ENV['ADAPTER'] != name.to_s
|
7
8
|
|
8
|
-
lib = "do_#{name}"
|
9
|
-
|
10
9
|
begin
|
11
|
-
gem lib, '~>0.9.7'
|
12
|
-
require lib
|
13
10
|
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
14
11
|
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
15
12
|
# DataObjects::Sqlite3.logger = DataObjects::Logger.new(Pathname(__FILE__).dirname+'dm.log',0)
|
16
13
|
true
|
17
|
-
rescue
|
18
|
-
warn "Could not load #{
|
14
|
+
rescue LoadError => e
|
15
|
+
warn "Could not load do_#{name}: #{e}"
|
19
16
|
false
|
20
17
|
end
|
21
18
|
end
|
data/tasks/install.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
def sudo_gem(cmd)
|
2
|
+
sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
|
3
|
+
end
|
4
|
+
|
5
|
+
desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
6
|
+
task :install => [ :package ] do
|
7
|
+
sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
|
11
|
+
task :uninstall => [ :clobber ] do
|
12
|
+
sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
|
13
|
+
end
|
data/tasks/spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
gem 'rspec', '~>1.1.11'
|
3
|
+
require 'spec'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
task :default => [ :spec ]
|
7
|
+
|
8
|
+
desc 'Run specifications'
|
9
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
10
|
+
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
11
|
+
t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
|
12
|
+
|
13
|
+
begin
|
14
|
+
gem 'rcov', '~>0.8'
|
15
|
+
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
16
|
+
t.rcov_opts << '--exclude' << 'spec'
|
17
|
+
t.rcov_opts << '--text-summary'
|
18
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
19
|
+
rescue LoadError
|
20
|
+
# rcov not installed
|
21
|
+
end
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
# rspec not installed
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-adjust
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sindre Aarsaether
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-07 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,19 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: hoe
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.8.2
|
23
|
+
version: 0.9.8
|
34
24
|
version:
|
35
25
|
description: DataMapper plugin providing methods to increment and decrement properties
|
36
26
|
email:
|
@@ -43,6 +33,7 @@ extra_rdoc_files:
|
|
43
33
|
- README.txt
|
44
34
|
- LICENSE
|
45
35
|
- TODO
|
36
|
+
- History.txt
|
46
37
|
files:
|
47
38
|
- History.txt
|
48
39
|
- LICENSE
|
@@ -55,10 +46,13 @@ files:
|
|
55
46
|
- lib/dm-adjust/collection.rb
|
56
47
|
- lib/dm-adjust/model.rb
|
57
48
|
- lib/dm-adjust/repository.rb
|
49
|
+
- lib/dm-adjust/resource.rb
|
58
50
|
- lib/dm-adjust/version.rb
|
59
51
|
- spec/integration/adjust_spec.rb
|
60
52
|
- spec/spec.opts
|
61
53
|
- spec/spec_helper.rb
|
54
|
+
- tasks/install.rb
|
55
|
+
- tasks/spec.rb
|
62
56
|
has_rdoc: true
|
63
57
|
homepage: http://github.com/sam/dm-more/tree/master/dm-adjust
|
64
58
|
post_install_message:
|