tainbox 2.0.0 → 2.1.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
  SHA1:
3
- metadata.gz: 587d2c7eaf022075b72228971c55ff7bf82b44e3
4
- data.tar.gz: 7211a25c69d04a92b4df7ff41e196246bd1fb785
3
+ metadata.gz: c6c7d2f828d08390d1a8190b447beeef3d4382e4
4
+ data.tar.gz: '07296a7790ec0f77824377574f15f749c9b11acb'
5
5
  SHA512:
6
- metadata.gz: a3a2dbb3569b68aa02ca22744affdba95503fce446822a6ef0c3aa68ffe535f5ab372fe077c51868741ec0525e33fd66aec735ff8c0457a83ffd3c32a25d14f4
7
- data.tar.gz: 23a7c04b92cdcc42de4efb1e5f6f054dbf190a052516076fb26073cfccd969ef229ecab3d2799080356bf05fd53973a7e8637e16e798acc359ca411e54cd6a27
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
@@ -1,3 +1,3 @@
1
1
  module Tainbox
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
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.0.0
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: 2016-09-18 00:00:00.000000000 Z
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.4.6
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: