dynomite 1.2.0 → 1.2.1

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: f7ffbee55e643480271f74155ba0e255875a13c28efc7a133da1d9eb23280ac9
4
- data.tar.gz: 6125daeb754588170f4150e90b8de7b67259b4254ce5780128321f0b83e67cce
3
+ metadata.gz: 86f0dd2d67b74fad780ef023ce7d4dcf40b4ee1741ca57fa730d9c5d3a615a96
4
+ data.tar.gz: d5f0f59d7761708f8ddb00efdd9bc82d9803234ba6fa4b1dda3486aae9210f60
5
5
  SHA512:
6
- metadata.gz: 4d2f33a6a016d9e689df6b68bcdd12dc8a93a435ddc5b3d41bb821c9aa86ca548d65ac6615a071e9493a955851fa3b917ee3db7c00e8c4f9354bbf576a5c5d2f
7
- data.tar.gz: cb7b866347a3b8dab6bc1552d1bf0d07469832d2a451c67539b8914d92229cd7ee72a430262fe2f0017f990dffe6b65005b106b210852d727149cf748b483a2b
6
+ metadata.gz: b32a45f367418c5d825bf294c1095949b963ea9abc86aafb3a3529c3097789cb723bc7f53940774c492b8512ddaf4e36746e3150520ca6cc796b7046db634a00
7
+ data.tar.gz: ed3daf9d3667901038c4aa66884e2883d8d7cd6ef675212818b715ba539c834e57bb0832ab02b4fc376ced1a86b68735499638f177e765231b635d2383d371f3
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.2.1]
7
+ - #10 from gotchane/fix-readme-about-validation
8
+ - #8 from patchkit-net/feature/replace-return-self
9
+ - #9 from patchkit-net/feature/custom-errors
10
+ - Change Item#replace method to return self
11
+ - Add custom Dynomite::Errors::ValidationError and Dynomite::Errors::ReservedWordError
12
+ fixing rspec warnings.
13
+
6
14
  ## [1.2.0]
7
15
  - #7 from patchkit-net/feature/validations
8
16
  - Add a way to quickly define getters and setters using `column` method
data/README.md CHANGED
@@ -128,8 +128,8 @@ class Post < Dynomite::Item
128
128
 
129
129
  column :id, :name # needed
130
130
 
131
- validate :id, presence: true
132
- validate :name, presence: true
131
+ validates :id, presence: true
132
+ validates :name, presence: true
133
133
  end
134
134
  ```
135
135
 
@@ -18,6 +18,7 @@ module Dynomite
18
18
  autoload :Core, "dynomite/core"
19
19
  autoload :Erb, "dynomite/erb"
20
20
  autoload :Log, "dynomite/log"
21
+ autoload :Errors, "dynomite/errors"
21
22
 
22
23
  extend Core
23
24
  end
@@ -0,0 +1,15 @@
1
+ module Dynomite
2
+ module Errors
3
+ class ValidationError < StandardError
4
+ def initialize(msg)
5
+ super
6
+ end
7
+ end
8
+
9
+ class ReservedWordError < StandardError
10
+ def initialize(msg)
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -41,6 +41,7 @@ module Dynomite
41
41
  class Item
42
42
  include Log
43
43
  include DbConfig
44
+ include Errors
44
45
 
45
46
  def initialize(attrs={})
46
47
  @attrs = attrs
@@ -79,12 +80,13 @@ module Dynomite
79
80
  attrs = self.class.replace(@attrs)
80
81
 
81
82
  @attrs = attrs # refresh attrs because it now has the id
83
+ self
82
84
  end
83
85
 
84
86
  # Similar to replace, but raises an error on failed validation.
85
87
  # Works that way only if ActiveModel::Validations are included
86
88
  def replace!(hash={})
87
- raise "Validation failed: #{errors.full_messages.join(', ')}" unless replace(hash)
89
+ raise ValidationError, "Validation failed: #{errors.full_messages.join(', ')}" unless replace(hash)
88
90
  end
89
91
 
90
92
  def find(id)
@@ -321,7 +323,9 @@ module Dynomite
321
323
 
322
324
  # @see Item.column
323
325
  def self.add_column(name)
324
- raise "'#{name}' is a reserved word" if Dynomite::RESERVED_WORDS.include?(name)
326
+ if Dynomite::RESERVED_WORDS.include?(name)
327
+ raise ReservedWordError, "'#{name}' is a reserved word"
328
+ end
325
329
 
326
330
  define_method(name) do
327
331
  @attrs[name.to_s]
@@ -1,3 +1,3 @@
1
1
  module Dynomite
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynomite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-12 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,6 +102,7 @@ files:
102
102
  - lib/dynomite/core.rb
103
103
  - lib/dynomite/db_config.rb
104
104
  - lib/dynomite/erb.rb
105
+ - lib/dynomite/errors.rb
105
106
  - lib/dynomite/item.rb
106
107
  - lib/dynomite/log.rb
107
108
  - lib/dynomite/migration.rb