dm-adjust 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Sindre Aarsaether
1
+ Copyright (c) 2009 Sindre Aarsaether
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,24 +1,29 @@
1
- require 'pathname'
1
+ require 'rubygems'
2
+ require 'rake'
2
3
 
3
- ROOT = Pathname(__FILE__).dirname.expand_path
4
- JRUBY = RUBY_PLATFORM =~ /java/
5
- WINDOWS = Gem.win_platform?
6
- SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
4
+ begin
5
+ gem 'jeweler', '~> 1.4'
6
+ require 'jeweler'
7
7
 
8
- require ROOT + 'lib/dm-adjust/version'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = 'dm-adjust'
10
+ gem.summary = 'DataMapper plugin providing methods to increment and decrement properties'
11
+ gem.description = gem.summary
12
+ gem.email = 'sindre [a] identu [d] no'
13
+ gem.homepage = 'http://github.com/datamapper/dm-more/tree/master/%s' % gem.name
14
+ gem.authors = [ 'Sindre Aarsaether' ]
9
15
 
10
- AUTHOR = 'Sindre Aarsaether'
11
- EMAIL = 'sindre [a] identu [d] no'
12
- GEM_NAME = 'dm-adjust'
13
- GEM_VERSION = DataMapper::Adjust::VERSION
14
- GEM_DEPENDENCIES = [['dm-core', GEM_VERSION]]
15
- GEM_CLEAN = %w[ log pkg coverage ]
16
- GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.rdoc LICENSE TODO History.rdoc ] }
16
+ gem.rubyforge_project = 'datamapper'
17
17
 
18
- PROJECT_NAME = 'datamapper'
19
- PROJECT_URL = "http://github.com/datamapper/dm-more/tree/master/#{GEM_NAME}"
20
- PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin providing methods to increment and decrement properties'
18
+ gem.add_dependency 'dm-core', '~> 0.10.2'
21
19
 
22
- [ ROOT, ROOT.parent ].each do |dir|
23
- Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
20
+ gem.add_development_dependency 'rspec', '~> 1.2.9'
21
+ gem.add_development_dependency 'yard', '~> 0.4.0'
22
+ end
23
+
24
+ Jeweler::GemcutterTasks.new
25
+
26
+ FileList['tasks/**/*.rake'].each { |task| import task }
27
+ rescue LoadError
28
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
24
29
  end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.10.2
data/dm-adjust.gemspec ADDED
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dm-adjust}
8
+ s.version = "0.10.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sindre Aarsaether"]
12
+ s.date = %q{2009-12-11}
13
+ s.description = %q{DataMapper plugin providing methods to increment and decrement properties}
14
+ s.email = %q{sindre [a] identu [d] no}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "dm-adjust.gemspec",
25
+ "lib/dm-adjust.rb",
26
+ "lib/dm-adjust/adapters/data_objects_adapter.rb",
27
+ "lib/dm-adjust/collection.rb",
28
+ "lib/dm-adjust/model.rb",
29
+ "lib/dm-adjust/repository.rb",
30
+ "lib/dm-adjust/resource.rb",
31
+ "spec/integration/adjust_spec.rb",
32
+ "spec/rcov.opts",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb",
35
+ "tasks/ci.rake",
36
+ "tasks/metrics.rake",
37
+ "tasks/spec.rake",
38
+ "tasks/yard.rake",
39
+ "tasks/yardstick.rake"
40
+ ]
41
+ s.homepage = %q{http://github.com/datamapper/dm-more/tree/master/dm-adjust}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubyforge_project = %q{datamapper}
45
+ s.rubygems_version = %q{1.3.5}
46
+ s.summary = %q{DataMapper plugin providing methods to increment and decrement properties}
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.2"])
54
+ s.add_development_dependency(%q<rspec>, ["~> 1.2.9"])
55
+ s.add_development_dependency(%q<yard>, ["~> 0.4.0"])
56
+ else
57
+ s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
58
+ s.add_dependency(%q<rspec>, ["~> 1.2.9"])
59
+ s.add_dependency(%q<yard>, ["~> 0.4.0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
63
+ s.add_dependency(%q<rspec>, ["~> 1.2.9"])
64
+ s.add_dependency(%q<yard>, ["~> 0.4.0"])
65
+ end
66
+ end
67
+
data/lib/dm-adjust.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require 'dm-adjust/adapters/data_objects_adapter'
2
2
  require 'dm-adjust/collection'
3
3
  require 'dm-adjust/model'
4
- require 'dm-adjust/query/conditions/comparison'
5
4
  require 'dm-adjust/repository'
6
5
  require 'dm-adjust/resource'
7
- require 'dm-adjust/version'
@@ -1,7 +1,9 @@
1
1
  module DataMapper
2
2
  module Adapters
3
3
  class DataObjectsAdapter < AbstractAdapter
4
- def adjust(attributes, query)
4
+ def adjust(attributes, collection)
5
+ query = collection.query
6
+
5
7
  # TODO: if the query contains any links, a limit or an offset
6
8
  # use a subselect to get the rows to be updated
7
9
 
@@ -19,7 +21,7 @@ module DataMapper
19
21
 
20
22
  bind_values.concat(conditions_bind_values)
21
23
 
22
- execute(statement, *bind_values)
24
+ execute(statement, *bind_values).affected_rows
23
25
  end
24
26
 
25
27
  module SQL
@@ -19,65 +19,33 @@ module DataMapper
19
19
  def adjust!(attributes = {}, reload = false)
20
20
  return true if attributes.empty?
21
21
 
22
- adjust_attributes = {}
23
-
24
- model.properties(repository.name).values_at(*attributes.keys).each do |property|
25
- adjust_attributes[property] = attributes[property.name] if property
26
- end
27
-
28
- if loaded?
29
- each { |r| attributes.each_pair { |a, v| r.attribute_set(a, r.send(a) + v) }; r.save }
30
- return true
31
- end
32
-
33
- # if none of the attributes that are adjusted is part of the collection-query
34
- # there is no need to load the collection (it will not change after adjustment)
35
- # if the query contains a raw sql-string, we cannot (truly) know, and must load.
36
- unless altered = query.raw?
37
- query.conditions.each_node do |comparison|
38
- altered = true
39
- end
40
- end
41
-
42
- identity_map = repository.identity_map(model)
43
- key_properties = model.key(repository.name)
44
-
45
- if identity_map.any? && reload
46
- reload_query = key_properties.zip(identity_map.keys.transpose).to_hash
47
-
48
- if altered
49
- keys = all(reload_query.merge(:fields => key_properties)).map { |r| r.key }
50
- reload_query = model.key(repository.name).zip(keys.transpose).to_hash
51
- end
22
+ reload_conditions = if reload
23
+ model_key = model.key(repository.name)
24
+ Query.target_conditions(self, model_key, model_key)
52
25
  end
53
26
 
54
- repository.adjust(adjust_attributes, scoped_query({}))
27
+ adjust_attributes = adjust_attributes(attributes)
28
+ repository.adjust(adjust_attributes, self)
55
29
 
56
- # Reload affected objects in identity-map. if collection was affected, dont use the scope.
57
- if reload_query && reload_query.any?
58
- (altered ? model : self).all(reload_query).reload(:fields => attributes.keys)
30
+ if reload_conditions
31
+ @query.clear
32
+ @query.update(:conditions => reload_conditions)
33
+ self.reload
59
34
  end
60
35
 
61
- # if preload was set to false, and collection was affected by updates,
62
- # something is now officially borked. We'll try the best we can (still many cases this is borked for)
63
- if altered
64
- query.conditions.each_node do |comparison|
65
- next unless adjustment = adjust_attributes[comparison.subject]
36
+ true
37
+ end
66
38
 
67
- next unless key = [ comparison.subject, comparison.subject.name ].detect do |key|
68
- query.options.key?(key)
69
- end
39
+ private
70
40
 
71
- value = case value = comparison.value
72
- when Numeric then comparison.value + adjustment
73
- when Range then (value.first + adjustment)..(value.last + adjustment)
74
- end
41
+ def adjust_attributes(attributes)
42
+ adjust_attributes = {}
75
43
 
76
- query.update(key => value)
77
- end
44
+ model.properties(repository.name).values_at(*attributes.keys).each do |property|
45
+ adjust_attributes[property] = attributes[property.name]
78
46
  end
79
47
 
80
- true
48
+ adjust_attributes
81
49
  end
82
50
  end # Collection
83
51
  end # DataMapper
@@ -1,8 +1,8 @@
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!'
4
+ def adjust(*args)
5
+ all.adjust(*args)
6
6
  end
7
7
 
8
8
  ##
@@ -14,8 +14,8 @@ module DataMapper
14
14
  #
15
15
  # @param attributes <Hash> A hash of attributes to adjust, and their adjustment
16
16
  # @public
17
- def adjust!(attributes,reload=false)
18
- all.adjust!(attributes,reload)
17
+ def adjust!(*args)
18
+ all.adjust!(*args)
19
19
  end
20
20
  end # Model
21
21
  end # DataMapper
@@ -1,23 +1,23 @@
1
1
  module DataMapper
2
2
  module Resource
3
3
  def adjust(attributes = {}, reload = false)
4
- raise NotImplementedError, 'adjust *with* validations has not be written yet, try adjust!'
4
+ collection_for_self.adjust(*args)
5
5
  end
6
6
 
7
- def adjust!(attributes = {}, reload = false)
8
- return true if attributes.empty?
7
+ def adjust!(*args)
8
+ collection_for_self.adjust!(*args)
9
+ end
10
+
11
+ private
9
12
 
13
+ def adjust_attributes(attributes)
10
14
  adjust_attributes = {}
11
15
 
12
16
  model.properties(repository.name).values_at(*attributes.keys).each do |property|
13
- adjust_attributes[property] = attributes[property.name] if property
17
+ adjust_attributes[property] = attributes[property.name]
14
18
  end
15
19
 
16
- repository.adapter.adjust(adjust_attributes, query)
17
-
18
- collection.reload(:fields => adjust_attributes.keys) if reload
19
-
20
- true
20
+ adjust_attributes
21
21
  end
22
22
  end # Resource
23
23
  end # DataMapper
data/spec/rcov.opts ADDED
@@ -0,0 +1,6 @@
1
+ --exclude "spec"
2
+ --sort coverage
3
+ --callsites
4
+ --xrefs
5
+ --profile
6
+ --text-summary
data/spec/spec.opts CHANGED
@@ -1,2 +1,4 @@
1
1
  --colour
2
2
  --loadby random
3
+ --format profile
4
+ --backtrace
data/tasks/ci.rake ADDED
@@ -0,0 +1 @@
1
+ task :ci => [ :verify_measurements, 'metrics:all' ]
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'metric_fu'
3
+ rescue LoadError
4
+ namespace :metrics do
5
+ task :all do
6
+ abort 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
7
+ end
8
+ end
9
+ end
10
+
11
+ begin
12
+ require 'reek/adapters/rake_task'
13
+
14
+ Reek::RakeTask.new do |t|
15
+ t.fail_on_error = true
16
+ t.verbose = false
17
+ t.source_files = 'lib/**/*.rb'
18
+ end
19
+ rescue LoadError
20
+ task :reek do
21
+ abort 'Reek is not available. In order to run reek, you must: gem install reek'
22
+ end
23
+ end
24
+
25
+ begin
26
+ require 'roodi'
27
+ require 'roodi_task'
28
+
29
+ RoodiTask.new do |t|
30
+ t.verbose = false
31
+ end
32
+ rescue LoadError
33
+ task :roodi do
34
+ abort 'Roodi is not available. In order to run roodi, you must: gem install roodi'
35
+ end
36
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,41 @@
1
+ spec_defaults = lambda do |spec|
2
+ spec.pattern = 'spec/**/*_spec.rb'
3
+ spec.libs << 'lib' << 'spec'
4
+ spec.spec_opts << '--options' << 'spec/spec.opts'
5
+ end
6
+
7
+ begin
8
+ require 'spec/rake/spectask'
9
+
10
+ Spec::Rake::SpecTask.new(:spec, &spec_defaults)
11
+ rescue LoadError
12
+ task :spec do
13
+ abort 'rspec is not available. In order to run spec, you must: gem install rspec'
14
+ end
15
+ end
16
+
17
+ begin
18
+ require 'rcov'
19
+ require 'spec/rake/verify_rcov'
20
+
21
+ Spec::Rake::SpecTask.new(:rcov) do |rcov|
22
+ spec_defaults.call(rcov)
23
+ rcov.rcov = true
24
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
25
+ end
26
+
27
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
28
+ rcov.threshold = 100
29
+ end
30
+ rescue LoadError
31
+ %w[ rcov verify_rcov ].each do |name|
32
+ task name do
33
+ abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
34
+ end
35
+ end
36
+ end
37
+
38
+ task :spec => :check_dependencies
39
+ task :rcov => :check_dependencies
40
+
41
+ task :default => :spec
data/tasks/yard.rake ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'yard'
3
+
4
+ YARD::Rake::YardocTask.new
5
+ rescue LoadError
6
+ task :yard do
7
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'pathname'
3
+ require 'yardstick/rake/measurement'
4
+ require 'yardstick/rake/verify'
5
+
6
+ # yardstick_measure task
7
+ Yardstick::Rake::Measurement.new
8
+
9
+ # verify_measurements task
10
+ Yardstick::Rake::Verify.new do |verify|
11
+ verify.threshold = 100
12
+ end
13
+ rescue LoadError
14
+ %w[ yardstick_measure verify_measurements ].each do |name|
15
+ task name.to_s do
16
+ abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
17
+ end
18
+ end
19
+ 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.10.1
4
+ version: 0.10.2
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: 2009-09-30 00:00:00 -07:00
12
+ date: 2009-12-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,50 +18,67 @@ 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.10.1
23
+ version: 0.10.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: yard
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.4.0
24
44
  version:
25
45
  description: DataMapper plugin providing methods to increment and decrement properties
26
- email:
27
- - sindre [a] identu [d] no
46
+ email: sindre [a] identu [d] no
28
47
  executables: []
29
48
 
30
49
  extensions: []
31
50
 
32
51
  extra_rdoc_files:
33
- - README.rdoc
34
52
  - LICENSE
35
- - TODO
36
- - History.rdoc
53
+ - README.rdoc
37
54
  files:
38
- - History.rdoc
39
55
  - LICENSE
40
- - Manifest.txt
41
56
  - README.rdoc
42
57
  - Rakefile
43
- - TODO
58
+ - VERSION
59
+ - dm-adjust.gemspec
44
60
  - lib/dm-adjust.rb
45
61
  - lib/dm-adjust/adapters/data_objects_adapter.rb
46
62
  - lib/dm-adjust/collection.rb
47
63
  - lib/dm-adjust/model.rb
48
- - lib/dm-adjust/query/conditions/comparison.rb
49
64
  - lib/dm-adjust/repository.rb
50
65
  - lib/dm-adjust/resource.rb
51
- - lib/dm-adjust/version.rb
52
66
  - spec/integration/adjust_spec.rb
67
+ - spec/rcov.opts
53
68
  - spec/spec.opts
54
69
  - spec/spec_helper.rb
55
- - tasks/install.rb
56
- - tasks/spec.rb
70
+ - tasks/ci.rake
71
+ - tasks/metrics.rake
72
+ - tasks/spec.rake
73
+ - tasks/yard.rake
74
+ - tasks/yardstick.rake
57
75
  has_rdoc: true
58
76
  homepage: http://github.com/datamapper/dm-more/tree/master/dm-adjust
59
77
  licenses: []
60
78
 
61
79
  post_install_message:
62
80
  rdoc_options:
63
- - --main
64
- - README.rdoc
81
+ - --charset=UTF-8
65
82
  require_paths:
66
83
  - lib
67
84
  required_ruby_version: !ruby/object:Gem::Requirement
data/History.rdoc DELETED
@@ -1,27 +0,0 @@
1
- === 0.10.1 / 2009-09-30
2
-
3
- * No changes this version
4
-
5
- === 0.10.0 / 2009-09-15
6
-
7
- * Updated to work with dm-core 0.10.0
8
-
9
- === 0.9.11 / 2009-03-29
10
-
11
- * No changes this version
12
-
13
- === 0.9.10 / 2009-01-19
14
-
15
- * No changes this version
16
-
17
- === 0.9.9 / 2009-01-04
18
-
19
- * No changes this version
20
-
21
- === 0.9.8 / 2008-12-07
22
-
23
- * 3 minor enhancements:
24
-
25
- * Added Resource#adjust! method
26
- * Added Resource#adjust and Model#adjust (validation respecting) stubs
27
- * Preparations for dkubb/dm-core
data/Manifest.txt DELETED
@@ -1,19 +0,0 @@
1
- History.rdoc
2
- LICENSE
3
- Manifest.txt
4
- README.rdoc
5
- Rakefile
6
- TODO
7
- lib/dm-adjust.rb
8
- lib/dm-adjust/adapters/data_objects_adapter.rb
9
- lib/dm-adjust/collection.rb
10
- lib/dm-adjust/model.rb
11
- lib/dm-adjust/query/conditions/comparison.rb
12
- lib/dm-adjust/repository.rb
13
- lib/dm-adjust/resource.rb
14
- lib/dm-adjust/version.rb
15
- spec/integration/adjust_spec.rb
16
- spec/spec.opts
17
- spec/spec_helper.rb
18
- tasks/install.rb
19
- tasks/spec.rb
data/TODO DELETED
File without changes
@@ -1,25 +0,0 @@
1
- module DataMapper
2
- class Query
3
- module Conditions
4
- class AbstractOperation
5
- def each_node
6
- operands = self.operands.dup
7
-
8
- while operand = operands.shift
9
- if operand.respond_to?(:operands)
10
- operands.concat(operand.operands)
11
- else
12
- yield operand
13
- end
14
- end
15
- end
16
- end
17
-
18
- class AbstractComparison
19
- # this is necessary to allow dm-adjust to change the conditions
20
- # of the query in an existing collection
21
- attr_accessor :value
22
- end
23
- end
24
- end
25
- end
@@ -1,5 +0,0 @@
1
- module DataMapper
2
- module Adjust
3
- VERSION = '0.10.1'.freeze
4
- end
5
- end
data/tasks/install.rb DELETED
@@ -1,13 +0,0 @@
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 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 DELETED
@@ -1,25 +0,0 @@
1
- begin
2
- require 'spec/rake/spectask'
3
-
4
- task :default => [ :spec ]
5
-
6
- desc 'Run specifications'
7
- Spec::Rake::SpecTask.new(:spec) do |t|
8
- t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
9
- t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
10
-
11
- begin
12
- require 'rcov'
13
- t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
14
- t.rcov_opts << '--exclude' << 'spec'
15
- t.rcov_opts << '--text-summary'
16
- t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
17
- rescue LoadError
18
- # rcov not installed
19
- rescue SyntaxError
20
- # rcov syntax invalid
21
- end
22
- end
23
- rescue LoadError
24
- # rspec not installed
25
- end