easy_serializer 0.3.0 → 0.3.1
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/.gitignore +1 -0
- data/README.md +13 -0
- data/lib/easy_serializer/base.rb +7 -5
- data/lib/easy_serializer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebcff111f3619af4f2814b418809a7811b63b6d8
|
4
|
+
data.tar.gz: aeae760e793004d0f50572ca4eb4bb98aa588dc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 552783179ccb762ab515aeb4a98a52f138dca208fbdac9b6723f1d1d006d76ec19065a61f1947031121d3f0dc3cb5f6fc8a05fafaea090b279a619fc548c821a
|
7
|
+
data.tar.gz: aa205fb92d1f7237ec6374c912c59537b6437b387a919a1bd9859fd9a0374c4ab6c2bb11a44b09ce93158ecc8fa914c654546b40e994a942d17d329cb8dc5afa
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -105,6 +105,19 @@ class BlockExample < EasySerializer::Base
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
```
|
108
|
+
**Passing options as a second argument:**
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
class OptionsSerializer < EasySerializer::Base
|
112
|
+
attribute :name
|
113
|
+
attribute :from_opts do
|
114
|
+
options[:hello]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
OptionsSerializer.call(OpenStruct.new(name: 'Dave'), hello: "hello with from options")
|
119
|
+
# => {:name=>"Dave", :from_opts=>"hello with from options"}
|
120
|
+
```
|
108
121
|
|
109
122
|
**Changing keys:**
|
110
123
|
|
data/lib/easy_serializer/base.rb
CHANGED
@@ -5,15 +5,16 @@ module EasySerializer
|
|
5
5
|
|
6
6
|
def_delegator :serialize, :to_json, :[]
|
7
7
|
|
8
|
-
attr_reader :object
|
9
|
-
def initialize(object)
|
8
|
+
attr_reader :object, :options
|
9
|
+
def initialize(object, options = {})
|
10
10
|
@object = object
|
11
|
+
@options = options
|
11
12
|
end
|
12
13
|
|
13
14
|
class << self
|
14
15
|
|
15
|
-
def call(
|
16
|
-
new(
|
16
|
+
def call(*args)
|
17
|
+
new(*args).serialize
|
17
18
|
end
|
18
19
|
alias_method :serialize, :call
|
19
20
|
alias_method :to_hash, :call
|
@@ -47,7 +48,8 @@ module EasySerializer
|
|
47
48
|
end
|
48
49
|
alias_method :to_h, :serialize
|
49
50
|
alias_method :to_hash, :serialize
|
50
|
-
|
51
|
+
|
52
|
+
def to_s; serialize.to_json end
|
51
53
|
|
52
54
|
def send_to_serializer(serializer, value)
|
53
55
|
return unless value
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Pañach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.5.2
|
112
|
+
rubygems_version: 2.5.2.2
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Semantic serializer for making easy serializing objects.
|