tainbox 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/tainbox/instance_methods.rb +8 -0
- data/lib/tainbox/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c7d2f828d08390d1a8190b447beeef3d4382e4
|
4
|
+
data.tar.gz: '07296a7790ec0f77824377574f15f749c9b11acb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08d34d82657a406d1c3543dda0152f40dfce57b8f2e7d21367ce6b5996b1b48940cd6b05f6986f29b5401170e40e343ba32f4d0a646f45565eb2a6d0c00959b3'
|
7
|
+
data.tar.gz: e279554e774bce99cc93ab49810054e72cea642a0ec82e95f49d21edc3a3c75e2ee26d06cc5a194009f575e70762be80afd65b8a6a4f32b5da51d9361b388f3f
|
data/README.md
CHANGED
@@ -25,6 +25,9 @@ person.attributes = {}
|
|
25
25
|
person.attributes # => { :name => "person_20", :age => 20 }
|
26
26
|
```
|
27
27
|
|
28
|
+
*NOTE* There are two ways to change attributes in bulk. attributes= replaces missing values
|
29
|
+
with nils or default values, while patch_attributes leaves missing attributes untouched.
|
30
|
+
|
28
31
|
## But what's wrong with Virtus?
|
29
32
|
|
30
33
|
Observe:
|
@@ -45,6 +45,14 @@ module Tainbox::InstanceMethods
|
|
45
45
|
tainbox_provided_attributes.include?(attribute.to_sym)
|
46
46
|
end
|
47
47
|
|
48
|
+
def patch_attributes(attributes)
|
49
|
+
if attributes.respond_to?(:to_h)
|
50
|
+
attributes.to_h.each { |key, value| send("#{key}=", value) if respond_to?("#{key}=") }
|
51
|
+
else
|
52
|
+
raise ArgumentError, 'Attributes can only be assigned via objects which respond to #to_h'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
48
56
|
def as_json(*args)
|
49
57
|
attributes.as_json(*args)
|
50
58
|
end
|
data/lib/tainbox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tainbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Gubitskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,11 +123,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.5.2
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Tainbox is a utility gem that can be used to inject attributes into ruby
|
130
130
|
objects. It is similar to Virtus, but works a bit more sensibly (hopefully) and
|
131
131
|
throws in some additional features
|
132
132
|
test_files: []
|
133
|
-
has_rdoc:
|