active_model_persistence 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4358309182de30b6d706336fdebb8d8e4b803d35cfc75c86074cb2fe96230a92
4
- data.tar.gz: 3003146bc077bacff57e3d62ee55fb4ced6a3cec443a6250bd27e1b59cb17285
3
+ metadata.gz: 5c9021a01608e4ac248001eafc0a7c2265ab82666bc33add62e9a3f3586f6bbf
4
+ data.tar.gz: 4225a766baeb076abce4a27cbde7d8c742f02e660632855198ba6dda7a20434f
5
5
  SHA512:
6
- metadata.gz: ec9030ea8eff12cf3d05bcaee715b846069cc4c7358c473c2688d198c73db949b79364089c10860a28b9a9ee83fe1a22f3d2bc049c4078026cfd2204d3b61082
7
- data.tar.gz: 74a2bcd9bf79fbd3747f365cf8c7c7059fec276d61e2880d36870daba6c2c12cb9e85d359d6216edff526c5f3a39da5f7e655272e06c8dbe89eb3de6c6781193
6
+ metadata.gz: 8499b0d13d3acafcd5b45df2d8c3d22a171f2f428f7b1d6de961855af7d18b839c0be9c40163bbf74bb91fa5f9956e62e37a7bcfe691eeac3eb6057508abb412
7
+ data.tar.gz: fa9bab5a614c233c7c505f7f66f181abf87787d51902322c88408fe8802334f701ef5b7742e01bfa80ab3352a4765e9b811da1ba6ee145e3a80496e80a3fbaa6
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ <!--
2
+ # @markup markdown
3
+ # @title Change Log
4
+ -->
5
+
6
+ # Change Log
7
+
8
+ The full change log is stored on [this project's GitHub releases page](https://github.com/jcouball/active_model_persistence/releases).
@@ -0,0 +1,12 @@
1
+ FROM rust
2
+
3
+ # Build the docker image (from this project's root directory):
4
+ # docker build --file Dockerfile.changelog-rs --tag changelog-rs .
5
+ #
6
+ # Use this image to output a changelog (from this project's root directory):
7
+ # docker run --rm --volume "$PWD:/worktree" changelog-rs v1.9.1 v1.10.0
8
+
9
+ RUN cargo install changelog-rs
10
+ WORKDIR /worktree
11
+
12
+ ENTRYPOINT ["/usr/local/cargo/bin/changelog-rs", "/worktree"]
@@ -14,6 +14,7 @@ module ActiveModelPersistence
14
14
  # attribute :id, :integer
15
15
  # attribute :name, :string
16
16
  # index :id, unique: true
17
+ # validates :id, presence: true
17
18
  # end
18
19
  #
19
20
  # # Creating a model instance with `.new` does not save it to the object store
@@ -274,6 +275,28 @@ module ActiveModelPersistence
274
275
  result != false
275
276
  end
276
277
 
278
+ # Calls #save and raises an error if #save returns false
279
+ #
280
+ # @example
281
+ # object = ModelExample.new(id: nil, name: 'James')
282
+ # object.save! #=> raises ObjectNotSavedError
283
+ #
284
+ # @param _options [Hash] save options (currently unused)
285
+ #
286
+ # @param block [Proc] a block to call after the save
287
+ #
288
+ # @yield [self] a block to call after the save
289
+ # @yieldparam saved_model [self] the model object after it was saved
290
+ # @yieldreturn [void]
291
+ #
292
+ # @raise [ObjectNotSavedError] if the model object was not saved
293
+ #
294
+ # @return [Boolean] returns true or raises an error
295
+ #
296
+ def save!(**options, &block)
297
+ save(**options, &block) || raise(ObjectNotSavedError.new('Failed to save the object', self))
298
+ end
299
+
277
300
  # Deletes the object from the object store
278
301
  #
279
302
  # This model object is frozen to reflect that no changes should be made
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ActiveModelPersistence
4
4
  # The version of the active_model_persistence gem
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
@@ -5,6 +5,8 @@ require 'active_model'
5
5
 
6
6
  # A set of mixins to add to ActiveModel classes to support persistence
7
7
  #
8
+ # @api public
9
+ #
8
10
  module ActiveModelPersistence
9
11
  # A base class for all ActiveModelPersistence errors
10
12
  class ModelError < StandardError; end
@@ -14,6 +16,33 @@ module ActiveModelPersistence
14
16
 
15
17
  # Raised when trying to add an object to an index when the key already exists in the index for another object
16
18
  class UniqueConstraintError < ModelError; end
19
+
20
+ # Raised when trying to save an invalid object
21
+ class ObjectNotSavedError < ModelError
22
+ # The object that was not saved
23
+ #
24
+ # @example
25
+ # object = Object.new
26
+ # error = ObjectNotSavedError.new('Invalid object', object)
27
+ # error.object == object #=> true
28
+ #
29
+ # @return [Object] The object that was not saved
30
+ #
31
+ attr_reader :object
32
+
33
+ # Create a new error
34
+ #
35
+ # @example
36
+ # ObjectNotSavedError.new('Invalid object', self)
37
+ #
38
+ # @param message [String] The error message
39
+ # @param object [Object] The object that was not saved
40
+ #
41
+ def initialize(message = nil, object = nil)
42
+ @object = object
43
+ super(message)
44
+ end
45
+ end
17
46
  end
18
47
 
19
48
  require_relative 'active_model_persistence/index'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_persistence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Couball
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -189,6 +189,8 @@ extra_rdoc_files: []
189
189
  files:
190
190
  - ".rspec"
191
191
  - ".rubocop.yml"
192
+ - CHANGELOG.md
193
+ - Dockerfile.changelog-rs
192
194
  - Gemfile
193
195
  - LICENSE.txt
194
196
  - README.md
@@ -227,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
229
  - !ruby/object:Gem::Version
228
230
  version: '0'
229
231
  requirements: []
230
- rubygems_version: 3.3.3
232
+ rubygems_version: 3.1.6
231
233
  signing_key:
232
234
  specification_version: 4
233
235
  summary: Adds in-memory persistence to ActiveModel models