simply_stored 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  Changelog
2
2
  =============
3
3
 
4
+ 0.6.0
5
+
6
+ - Ruby 1.9.2 compatible
7
+
8
+ - compatible with CouchPotato > 0.5 where the attributes are lazy loaded
9
+
10
+ - Depends on ActiveSupport/ActiveModel 3.x
11
+ --> Does not longer work with Rails 2.x !
12
+
4
13
  0.5.4
5
14
 
6
15
  - Add Rake task to compact all views in a given database:
data/Gemfile.lock CHANGED
@@ -1,13 +1,21 @@
1
1
  GEM
2
+ remote: http://rubygems.org/
2
3
  specs:
3
- activesupport (2.3.11)
4
- couch_potato (0.2.31.2)
5
- couchrest (>= 0.24)
4
+ activemodel (3.0.9)
5
+ activesupport (= 3.0.9)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activesupport (3.0.9)
9
+ builder (2.1.2)
10
+ couch_potato (0.5.0)
11
+ activemodel
12
+ couchrest (>= 1.0.1)
6
13
  json
7
14
  couchrest (1.0.1)
8
15
  json (>= 1.4.6)
9
16
  mime-types (>= 1.15)
10
17
  rest-client (>= 1.5.1)
18
+ i18n (0.5.0)
11
19
  json (1.4.6)
12
20
  mattmatt-validatable (1.8.4)
13
21
  mime-types (1.16)
@@ -27,8 +35,8 @@ PLATFORMS
27
35
  ruby
28
36
 
29
37
  DEPENDENCIES
30
- activesupport (= 2.3.11)
31
- couch_potato (= 0.2.31.2)
38
+ activesupport (~> 3.0.0)
39
+ couch_potato (= 0.5.0)
32
40
  couchrest (= 1.0.1)
33
41
  mattmatt-validatable (= 1.8.4)
34
42
  mocha
data/README.md CHANGED
@@ -17,6 +17,47 @@ Installation
17
17
 
18
18
  gem install simply_stored
19
19
 
20
+
21
+ #### Using with Rails
22
+
23
+ Create a config/couchdb.yml:
24
+
25
+ default: &default
26
+ validation_framework: :active_model # optional
27
+ split_design_documents_per_view: true # optional
28
+
29
+ development:
30
+ <<: *default
31
+ database: http://localhost:5984/development_db
32
+ test:
33
+ <<: *default
34
+ database: http://localhost:5984/test_db
35
+ production:
36
+ <<: *default
37
+ database: <%= ENV['DB_NAME'] %>
38
+
39
+ #### Rails 2.x
40
+
41
+ In config/environment.rb:
42
+
43
+ config.gem 'simply_stored', :source => 'http://gemcutter.org'
44
+ config.frameworks -= [:active_record] # if you do not need ActiveRecord any more
45
+
46
+ Please note that if you use Rails 2.x, you can only use SimplyStored until version 0.5.4. SimplyStored 0.6 and above require Rails 3.x.
47
+
48
+ #### Rails 3.x
49
+
50
+ Add to your Gemfile:
51
+
52
+ # gem 'rails' # we don't want to load activerecord so we can't require rails
53
+ gem 'railties'
54
+ gem 'actionpack'
55
+ gem 'actionmailer'
56
+ gem 'activemodel'
57
+ gem 'simply_stored', :require => 'simply_stored/couch'
58
+
59
+ Please also see the installation info of [CouchPotato](https://github.com/langalex/couch_potato)
60
+
20
61
  Usage
21
62
  =============
22
63
 
@@ -56,7 +56,6 @@ module SimplyStored
56
56
  @options.assert_valid_keys(:class_name)
57
57
 
58
58
  owner_clazz.class_eval do
59
- attr_reader "#{name}_id"
60
59
  attr_accessor "#{name}_id_was"
61
60
  property "#{name}_id"
62
61
 
@@ -74,17 +73,16 @@ module SimplyStored
74
73
  klass = self.class.get_class_from_name(self.class._find_property(name).options[:class_name])
75
74
  raise ArgumentError, "expected #{klass} got #{value.class}" unless value.nil? || value.is_a?(klass)
76
75
 
76
+ new_foreign_id = value.nil? ? nil : value.id
77
+
78
+ send("#{name}_id=", new_foreign_id)
77
79
  instance_variable_set("@#{name}", value)
78
- if value.nil?
79
- instance_variable_set("@#{name}_id", nil)
80
- else
81
- instance_variable_set("@#{name}_id", value.id)
82
- end
83
80
  end
84
81
 
85
- define_method "#{name}_id=" do |id|
82
+ define_method "#{name}_id=" do |new_foreign_id|
83
+ super
84
+ value = instance_variable_get("@#{name}")
86
85
  remove_instance_variable("@#{name}") if instance_variable_defined?("@#{name}")
87
- instance_variable_set("@#{name}_id", id)
88
86
  end
89
87
 
90
88
  define_method "#{name}_changed?" do
@@ -4,6 +4,12 @@ module CouchPotato
4
4
  private
5
5
 
6
6
  def reset_dirty_attributes
7
+ # active mode reset
8
+ @previously_changed = changes
9
+ @changed_attributes.clear
10
+ @forced_dirty = nil
11
+
12
+ # belongs_to properties reset
7
13
  self.class.properties.each do |property|
8
14
  if !property.respond_to?(:supports_dirty?) || property.supports_dirty?
9
15
  property.respond_to?(:reset_dirty_attribute) ? property.reset_dirty_attribute(self) :
@@ -13,4 +19,24 @@ module CouchPotato
13
19
  end
14
20
  end
15
21
  end
22
+ end
23
+
24
+ module CouchPotato
25
+ class Database
26
+
27
+ # the original implementation does not delete if callbacks are skipped
28
+ def destroy_document(document, run_callbacks = true)
29
+ if run_callbacks
30
+ document.run_callbacks :destroy do
31
+ document._deleted = true
32
+ database.delete_doc document.to_hash
33
+ end
34
+ else
35
+ document._deleted = true
36
+ database.delete_doc document.to_hash
37
+ end
38
+ document._id = nil
39
+ document._rev = nil
40
+ end
41
+ end
16
42
  end
@@ -81,7 +81,7 @@ module SimplyStored
81
81
  elsif options[:dependent] == :ignore
82
82
  # skip
83
83
  else # nullify
84
- value.send("#{self.class.foreign_key}=", nil)
84
+ value.send("#{self.class.foreign_key}=", nil)
85
85
  value.save(false)
86
86
  end
87
87
 
@@ -19,6 +19,8 @@ require 'simply_stored/couch/has_one'
19
19
  require 'simply_stored/couch/ext/couch_potato'
20
20
  require 'simply_stored/couch/views'
21
21
 
22
+ CouchPotato::Config.validation_framework = :validatable
23
+
22
24
  module SimplyStored
23
25
  module Couch
24
26
  def self.included(clazz)
@@ -30,8 +32,6 @@ module SimplyStored
30
32
 
31
33
  clazz.instance_eval do
32
34
  attr_accessor :_accessible_attributes, :_protected_attributes
33
- alias :simpledb_array :simpledb_string
34
- alias :simpledb_integer :simpledb_string
35
35
 
36
36
  view :all_documents, :key => :created_at
37
37
  end
@@ -84,34 +84,6 @@ module SimplyStored
84
84
  @auto_conflict_resolution_on_save = val
85
85
  end
86
86
 
87
- def simpledb_string(*names)
88
- names.each do |name|
89
- property name
90
- end
91
- end
92
-
93
- def simpledb_timestamp(*names)
94
- names.each do |name|
95
- property name, :type => Time
96
- end
97
- end
98
-
99
- def require_attributes(*names)
100
- names.each do |name|
101
- validates_presence_of name
102
- end
103
- end
104
-
105
- def require_inclusion_of(name, valid_set, options = {})
106
- options.update(:in => valid_set)
107
- validates_inclusion_of(name, options)
108
- end
109
-
110
- def require_format_of(attr, valid_regex, options = {})
111
- options.update(:with => valid_regex)
112
- validates_format_of(attr, options)
113
- end
114
-
115
87
  def method_missing(name, *args)
116
88
  if name.to_s =~ /^find_by/
117
89
  _define_find_by(name, *args)
@@ -29,12 +29,18 @@ module SimplyStored
29
29
  def destroy(override_soft_delete=false)
30
30
  check_and_destroy_dependents
31
31
  if self.class.soft_deleting_enabled? && !override_soft_delete
32
+ # soft-delete
32
33
  _mark_as_deleted
33
34
  else
34
- self.skip_callbacks = true if self.class.soft_deleting_enabled? && deleted?
35
- CouchPotato.database.destroy_document(self)
35
+ if self.class.soft_deleting_enabled? && deleted?
36
+ # really deleting a previously soft-deleted object - skipping callbacks
37
+ CouchPotato.database.destroy_document(self, false)
38
+ else # deleting a normal object or a soft-deletable object that was not soft-deleted before
39
+ CouchPotato.database.destroy_document(self, true)
40
+ end
36
41
  freeze
37
42
  end
43
+ self
38
44
  end
39
45
  alias :delete :destroy
40
46
 
@@ -65,8 +71,8 @@ module SimplyStored
65
71
  false
66
72
  end
67
73
  end
68
-
69
- protected
74
+
75
+ protected
70
76
 
71
77
  def retry_on_conflict(max_retries = 2, &blk)
72
78
  retry_count = 0
@@ -255,10 +261,10 @@ module SimplyStored
255
261
  end
256
262
 
257
263
  def _mark_as_deleted
258
- run_callbacks(:before_destroy)
259
- send("#{self.class.soft_delete_attribute}=", Time.now)
260
- save(false)
261
- run_callbacks(:after_destroy)
264
+ _run_destroy_callbacks do
265
+ send("#{self.class.soft_delete_attribute}=", Time.now)
266
+ save(false)
267
+ end
262
268
  end
263
269
 
264
270
  end
data/lib/simply_stored.rb CHANGED
@@ -1,12 +1,14 @@
1
- $:<<(File.expand_path(File.dirname(__FILE__) + "/lib"))
2
- require File.expand_path(File.dirname(__FILE__) + '/simply_stored/instance_methods')
3
- require File.expand_path(File.dirname(__FILE__) + '/simply_stored/storage')
4
- require File.expand_path(File.dirname(__FILE__) + '/simply_stored/class_methods_base')
1
+ unless defined?(SimplyStored)
2
+ $:<<(File.expand_path(File.dirname(__FILE__) + "/lib"))
3
+ require File.expand_path(File.dirname(__FILE__) + '/simply_stored/instance_methods')
4
+ require File.expand_path(File.dirname(__FILE__) + '/simply_stored/storage')
5
+ require File.expand_path(File.dirname(__FILE__) + '/simply_stored/class_methods_base')
5
6
 
6
- module SimplyStored
7
- VERSION = '0.5.4'
8
- class Error < RuntimeError; end
9
- class RecordNotFound < RuntimeError; end
10
- end
7
+ module SimplyStored
8
+ VERSION = '0.6.0'
9
+ class Error < RuntimeError; end
10
+ class RecordNotFound < RuntimeError; end
11
+ end
11
12
 
12
- require File.expand_path(File.dirname(__FILE__) + '/simply_stored/couch')
13
+ require File.expand_path(File.dirname(__FILE__) + '/simply_stored/couch')
14
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simply_stored
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 4
10
- version: 0.5.4
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mathias Meyer, Jonathan Weiss
@@ -15,13 +15,160 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-14 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-08-06 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: uuidtools
31
+ prerelease: false
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - "="
39
+ - !ruby/object:Gem::Version
40
+ hash: 63
41
+ segments:
42
+ - 1
43
+ - 8
44
+ - 4
45
+ version: 1.8.4
46
+ name: mattmatt-validatable
47
+ prerelease: false
48
+ type: :runtime
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ hash: 13
57
+ segments:
58
+ - 1
59
+ - 6
60
+ - 1
61
+ version: 1.6.1
22
62
  name: rest-client
23
63
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
64
+ type: :runtime
65
+ requirement: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - "="
71
+ - !ruby/object:Gem::Version
72
+ hash: 21
73
+ segments:
74
+ - 1
75
+ - 0
76
+ - 1
77
+ version: 1.0.1
78
+ name: couchrest
79
+ prerelease: false
80
+ type: :runtime
81
+ requirement: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - "="
87
+ - !ruby/object:Gem::Version
88
+ hash: 11
89
+ segments:
90
+ - 0
91
+ - 5
92
+ - 0
93
+ version: 0.5.0
94
+ name: couch_potato
95
+ prerelease: false
96
+ type: :runtime
97
+ requirement: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ name: shoulda
109
+ prerelease: false
110
+ type: :runtime
111
+ requirement: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ name: shoulda-addons
123
+ prerelease: false
124
+ type: :runtime
125
+ requirement: *id007
126
+ - !ruby/object:Gem::Dependency
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ name: mocha
137
+ prerelease: false
138
+ type: :runtime
139
+ requirement: *id008
140
+ - !ruby/object:Gem::Dependency
141
+ version_requirements: &id009 !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ~>
145
+ - !ruby/object:Gem::Version
146
+ hash: 7
147
+ segments:
148
+ - 3
149
+ - 0
150
+ - 0
151
+ version: 3.0.0
152
+ name: activesupport
153
+ prerelease: false
154
+ type: :runtime
155
+ requirement: *id009
156
+ - !ruby/object:Gem::Dependency
157
+ version_requirements: &id010 !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ name: right_aws
167
+ prerelease: false
168
+ type: :runtime
169
+ requirement: *id010
170
+ - !ruby/object:Gem::Dependency
171
+ version_requirements: &id011 !ruby/object:Gem::Requirement
25
172
  none: false
26
173
  requirements:
27
174
  - - ">="
@@ -32,12 +179,12 @@ dependencies:
32
179
  - 4
33
180
  - 2
34
181
  version: 1.4.2
182
+ name: rest-client
183
+ prerelease: false
35
184
  type: :runtime
36
- version_requirements: *id001
185
+ requirement: *id011
37
186
  - !ruby/object:Gem::Dependency
38
- name: couch_potato
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
187
+ version_requirements: &id012 !ruby/object:Gem::Requirement
41
188
  none: false
42
189
  requirements:
43
190
  - - ">="
@@ -48,12 +195,12 @@ dependencies:
48
195
  - 2
49
196
  - 15
50
197
  version: 0.2.15
198
+ name: couch_potato
199
+ prerelease: false
51
200
  type: :runtime
52
- version_requirements: *id002
201
+ requirement: *id012
53
202
  - !ruby/object:Gem::Dependency
54
- name: activesupport
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
203
+ version_requirements: &id013 !ruby/object:Gem::Requirement
57
204
  none: false
58
205
  requirements:
59
206
  - - ">="
@@ -62,12 +209,12 @@ dependencies:
62
209
  segments:
63
210
  - 0
64
211
  version: "0"
212
+ name: activesupport
213
+ prerelease: false
65
214
  type: :runtime
66
- version_requirements: *id003
215
+ requirement: *id013
67
216
  - !ruby/object:Gem::Dependency
68
- name: mattmatt-validatable
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
217
+ version_requirements: &id014 !ruby/object:Gem::Requirement
71
218
  none: false
72
219
  requirements:
73
220
  - - ">="
@@ -76,8 +223,10 @@ dependencies:
76
223
  segments:
77
224
  - 0
78
225
  version: "0"
226
+ name: mattmatt-validatable
227
+ prerelease: false
79
228
  type: :runtime
80
- version_requirements: *id004
229
+ requirement: *id014
81
230
  description: Convenience layer for CouchDB on top of CouchPotato.
82
231
  email: info@peritor.com
83
232
  executables: []
@@ -111,28 +260,12 @@ files:
111
260
  - lib/simply_stored/instance_methods.rb
112
261
  - lib/simply_stored/rake.rb
113
262
  - lib/simply_stored/storage.rb
114
- - test/active_model_compatibility_test.rb
115
- - test/belongs_to_test.rb
116
- - test/conflict_handling_test.rb
117
- - test/finder_test.rb
118
- - test/fixtures/couch.rb
119
- - test/has_and_belongs_to_many_test.rb
120
- - test/has_many_test.rb
121
- - test/has_one_test.rb
122
- - test/instance_lifecycle_test.rb
123
- - test/mass_assignment_protection_test.rb
124
- - test/s3_test.rb
125
- - test/soft_deletable_test.rb
126
- - test/test_helper.rb
127
- - test/validations_test.rb
128
- - test/views_test.rb
129
- has_rdoc: true
130
263
  homepage: http://github.com/peritor/simply_stored
131
264
  licenses: []
132
265
 
133
266
  post_install_message:
134
- rdoc_options:
135
- - --charset=UTF-8
267
+ rdoc_options: []
268
+
136
269
  require_paths:
137
270
  - lib
138
271
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -156,23 +289,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
289
  requirements: []
157
290
 
158
291
  rubyforge_project:
159
- rubygems_version: 1.3.7
292
+ rubygems_version: 1.8.7
160
293
  signing_key:
161
294
  specification_version: 3
162
295
  summary: Convenience layer for CouchDB
163
- test_files:
164
- - test/active_model_compatibility_test.rb
165
- - test/belongs_to_test.rb
166
- - test/conflict_handling_test.rb
167
- - test/finder_test.rb
168
- - test/fixtures/couch.rb
169
- - test/has_and_belongs_to_many_test.rb
170
- - test/has_many_test.rb
171
- - test/has_one_test.rb
172
- - test/instance_lifecycle_test.rb
173
- - test/mass_assignment_protection_test.rb
174
- - test/s3_test.rb
175
- - test/soft_deletable_test.rb
176
- - test/test_helper.rb
177
- - test/validations_test.rb
178
- - test/views_test.rb
296
+ test_files: []
297
+
@@ -1,23 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
-
3
- begin
4
- require 'active_model'
5
-
6
- class CouchModel
7
- include SimplyStored::Couch
8
- property :name
9
- validates_presence_of :name
10
- end
11
-
12
- class ActiveModelCompatibilityTest < Test::Unit::TestCase
13
- def setup
14
- @model = CouchModel.new
15
- end
16
- include ActiveModel::Lint::Tests
17
- end
18
-
19
- rescue LoadError
20
- puts "ActiveModel not installed, skipping lint tests."
21
- end
22
-
23
-