easy_serializer 0.3.0 → 0.3.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
  SHA1:
3
- metadata.gz: 750408c4938f35ca5abc691890dd714ce1c7c512
4
- data.tar.gz: 0e384b50fedd31913467e8544d3a2883bd57c776
3
+ metadata.gz: ebcff111f3619af4f2814b418809a7811b63b6d8
4
+ data.tar.gz: aeae760e793004d0f50572ca4eb4bb98aa588dc0
5
5
  SHA512:
6
- metadata.gz: aaadf06233f1b56ac4ed26074d89a836abf8f18d5b76c7401d37d4eecfdfdfbe687198ee23d067229f0843fabd6313c8dcb1d307690bb8a421b48afee9ecb4b5
7
- data.tar.gz: a315fec30af8d7984ecbc36ce840e2aa6b147640286b8f2f8201e765a3d48b08f4a5a6d2e3415bd4596c6b91c5203ac30c75548adeeef6d263d7ba8333ee89d5
6
+ metadata.gz: 552783179ccb762ab515aeb4a98a52f138dca208fbdac9b6723f1d1d006d76ec19065a61f1947031121d3f0dc3cb5f6fc8a05fafaea090b279a619fc548c821a
7
+ data.tar.gz: aa205fb92d1f7237ec6374c912c59537b6437b387a919a1bd9859fd9a0374c4ab6c2bb11a44b09ce93158ecc8fa914c654546b40e994a942d17d329cb8dc5afa
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /coverage/
9
9
  /tmp/
10
10
  easy_serializer*.gem
11
+ vendor
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
 
@@ -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(obj)
16
- new(obj).serialize
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
- alias_method :to_s, :to_json
51
+
52
+ def to_s; serialize.to_json end
51
53
 
52
54
  def send_to_serializer(serializer, value)
53
55
  return unless value
@@ -1,3 +1,3 @@
1
1
  module EasySerializer
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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-01-28 00:00:00.000000000 Z
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.