blueprinter 0.3.0 → 0.4.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 +5 -0
- data/lib/blueprinter/base.rb +21 -0
- data/lib/blueprinter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08abb9ba41c2c44993545fc879b4b94ab77394356f8cc82bc2fd8f11d37ad482'
|
4
|
+
data.tar.gz: d40666d3ed13b2bfca020a0ee37bde00876300ab856591b1e33d4cc6067f23c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4353599cf5f1b1320ad8bd930c23bbf046258c7767f4e27ff2d07faedc28fd031d29166959e2303588ac96140e06881bf761e2918e9cf40db0abe941cc2cb5a7
|
7
|
+
data.tar.gz: da2c78ad5210456490af49493a2b9043fde2aa73bd1a0642e6f2264c4ac004200e8d3a3a4058ec66cd1014252c4fd3f901ae6a771411c9720f8c1490ab7199f8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.4.0 - 2018/05/02
|
2
|
+
|
3
|
+
* [FEATURE] Add `render_as_hash` which will output a hash instead of
|
4
|
+
a JSON String. See PR #76 by @amayer171 and Issue #73.
|
5
|
+
|
1
6
|
## 0.3.0 - 2018/04/05
|
2
7
|
|
3
8
|
Sort of a breaking Change. Serializer classes has been renamed to Extractor. To upgrade, if you passed in a specific serializer to `field` or `identifier` such as:
|
data/lib/blueprinter/base.rb
CHANGED
@@ -131,6 +131,27 @@ module Blueprinter
|
|
131
131
|
jsonify(prepare(object, view_name: view_name, local_options: options))
|
132
132
|
end
|
133
133
|
|
134
|
+
# Generates a hash.
|
135
|
+
# Takes a required object and an optional view.
|
136
|
+
#
|
137
|
+
# @param object [Object] the Object to serialize upon.
|
138
|
+
# @param options [Hash] the options hash which requires a :view. Any
|
139
|
+
# additional key value pairs will be exposed during serialization.
|
140
|
+
# @option options [Symbol] :view Defaults to :default.
|
141
|
+
# The view name that corresponds to the group of
|
142
|
+
# fields to be serialized.
|
143
|
+
#
|
144
|
+
# @example Generating a hash with an extended view
|
145
|
+
# post = Post.all
|
146
|
+
# Blueprinter::Base.render_as_hash post, view: :extended
|
147
|
+
# # => [{id:1, title: Hello},{id:2, title: My Day}]
|
148
|
+
#
|
149
|
+
# @return [Hash]
|
150
|
+
def self.render_as_hash(object, options= {})
|
151
|
+
view_name = options.delete(:view) || :default
|
152
|
+
prepare(object, view_name: view_name, local_options: options)
|
153
|
+
end
|
154
|
+
|
134
155
|
# This is the magic method that converts complex objects into a simple hash
|
135
156
|
# ready for JSON conversion.
|
136
157
|
#
|
data/lib/blueprinter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprinter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hess
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|