tainbox 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +16 -0
- data/lib/tainbox/instance_methods.rb +5 -0
- data/lib/tainbox/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b459f82b88de885cb962e19571471ccb4a0d8af2
|
4
|
+
data.tar.gz: 1c3a37eb14e09eb5175714bbf4d1997d43b33d4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 670ef55e0098aff940d338026dad216770a316fd56da3abec04d20d3f08033dd25d0f16532decd662eda2ae47c53547b8f45db01e8a4b11a79755279038bc51f
|
7
|
+
data.tar.gz: d6f9860bc73c8c79f9dafb1a06a270aaeaeb67b817efb2f19f0b4ca99d5d3c0c34dfb1e290887cbf54c1cadff078ea924ae415c4134b823bdb5988ea114be221
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -107,6 +107,22 @@ Tainbox.define_converter(MyType) do
|
|
107
107
|
end
|
108
108
|
```
|
109
109
|
|
110
|
+
### `as_json`
|
111
|
+
|
112
|
+
``` ruby
|
113
|
+
class Person
|
114
|
+
include Tainbox
|
115
|
+
attribute :name
|
116
|
+
attribute :age
|
117
|
+
end
|
118
|
+
|
119
|
+
person = Person.new(name: 'John', age: 20)
|
120
|
+
|
121
|
+
person.as_json # => { 'name' => 'John', 'age' => 20 }
|
122
|
+
person.as_json(only: :name) # => { 'name' => 'John' }
|
123
|
+
person.as_json(except: :name) # => { 'age' => 20 }
|
124
|
+
```
|
125
|
+
|
110
126
|
### Suppressing tainbox initializer
|
111
127
|
|
112
128
|
If you don't want to pollute your class with tainbox initializer you can do:
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/hash/keys'
|
2
|
+
require 'active_support/core_ext/object/json'
|
2
3
|
|
3
4
|
require_relative 'extensions'
|
4
5
|
|
@@ -38,6 +39,10 @@ module Tainbox::InstanceMethods
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
def to_hash
|
43
|
+
attributes
|
44
|
+
end
|
45
|
+
|
41
46
|
def attribute_provided?(attribute)
|
42
47
|
tainbox_provided_attributes.include?(attribute.to_sym)
|
43
48
|
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: 0.
|
4
|
+
version: 1.0.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-
|
11
|
+
date: 2016-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|