representable 3.0.0 → 3.1.0
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 +5 -5
- data/.github/workflows/ci.yml +17 -0
- data/CHANGES.md +25 -0
- data/Gemfile +4 -12
- data/LICENSE +1 -1
- data/README.md +6 -6
- data/Rakefile +1 -6
- data/TODO +1 -3
- data/TODO-4.0.md +72 -0
- data/lib/representable.rb +19 -25
- data/lib/representable/binding.rb +32 -12
- data/lib/representable/cached.rb +1 -1
- data/lib/representable/coercion.rb +8 -6
- data/lib/representable/config.rb +13 -3
- data/lib/representable/debug.rb +23 -15
- data/lib/representable/declarative.rb +12 -7
- data/lib/representable/decorator.rb +1 -1
- data/lib/representable/definition.rb +7 -3
- data/lib/representable/deserializer.rb +5 -4
- data/lib/representable/for_collection.rb +1 -1
- data/lib/representable/hash.rb +9 -2
- data/lib/representable/hash/allow_symbols.rb +9 -11
- data/lib/representable/hash/binding.rb +1 -0
- data/lib/representable/hash/collection.rb +4 -2
- data/lib/representable/hash_methods.rb +3 -2
- data/lib/representable/insert.rb +1 -1
- data/lib/representable/json.rb +8 -7
- data/lib/representable/json/collection.rb +3 -0
- data/lib/representable/object.rb +1 -1
- data/lib/representable/object/binding.rb +5 -1
- data/lib/representable/option.rb +19 -0
- data/lib/representable/pipeline.rb +3 -2
- data/lib/representable/pipeline_factories.rb +4 -2
- data/lib/representable/populator.rb +1 -1
- data/lib/representable/represent.rb +1 -0
- data/lib/representable/serializer.rb +3 -2
- data/lib/representable/version.rb +1 -1
- data/lib/representable/virtus_coercion.rb +38 -0
- data/lib/representable/xml.rb +12 -10
- data/lib/representable/xml/binding.rb +19 -13
- data/lib/representable/xml/namespace.rb +122 -0
- data/lib/representable/yaml.rb +6 -2
- data/lib/representable/yaml/binding.rb +1 -0
- data/representable.gemspec +8 -9
- data/test/as_test.rb +7 -7
- data/test/binding_test.rb +14 -14
- data/test/cached_test.rb +59 -49
- data/test/class_test.rb +9 -9
- data/test/coercion_test.rb +33 -22
- data/test/config/inherit_test.rb +14 -14
- data/test/config_test.rb +20 -20
- data/test/decorator_scope_test.rb +4 -4
- data/test/decorator_test.rb +33 -20
- data/test/default_test.rb +8 -8
- data/test/defaults_options_test.rb +3 -3
- data/test/definition_test.rb +38 -40
- data/test/{example.rb → examples/example.rb} +0 -1
- data/test/examples/object.rb +1 -5
- data/test/exec_context_test.rb +8 -8
- data/test/features_test.rb +6 -6
- data/test/filter_test.rb +8 -8
- data/test/for_collection_test.rb +10 -10
- data/test/generic_test.rb +13 -13
- data/test/getter_setter_test.rb +5 -5
- data/test/hash_bindings_test.rb +1 -1
- data/test/hash_test.rb +45 -23
- data/test/heritage_test.rb +16 -13
- data/test/if_test.rb +9 -9
- data/test/include_exclude_test.rb +14 -14
- data/test/inherit_test.rb +18 -18
- data/test/inline_test.rb +24 -24
- data/test/instance_test.rb +31 -31
- data/test/is_representable_test.rb +10 -10
- data/test/json_test.rb +29 -7
- data/test/lonely_test.rb +31 -31
- data/test/nested_test.rb +13 -13
- data/test/object_test.rb +9 -9
- data/test/option_test.rb +36 -0
- data/test/parse_pipeline_test.rb +3 -5
- data/test/pipeline_test.rb +50 -50
- data/test/populator_test.rb +18 -18
- data/test/prepare_test.rb +4 -4
- data/test/private_options_test.rb +2 -2
- data/test/reader_writer_test.rb +2 -2
- data/test/render_nil_test.rb +2 -2
- data/test/represent_test.rb +14 -14
- data/test/representable_test.rb +34 -36
- data/test/schema_test.rb +8 -11
- data/test/serialize_deserialize_test.rb +2 -2
- data/test/skip_test.rb +14 -14
- data/test/stringify_hash_test.rb +3 -3
- data/test/test_helper.rb +26 -14
- data/test/uncategorized_test.rb +10 -10
- data/test/user_options_test.rb +4 -4
- data/test/virtus_coercion_test.rb +52 -0
- data/test/wrap_test.rb +19 -19
- data/test/xml_bindings_test.rb +0 -4
- data/test/xml_namespace_test.rb +186 -0
- data/test/xml_test.rb +103 -43
- data/test/yaml_test.rb +51 -26
- metadata +101 -39
- data/.travis.yml +0 -7
- data/lib/representable/TODO.getting_serious +0 -11
- data/lib/representable/autoload.rb +0 -10
- data/test/mongoid_test.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 434f6b67a146dfc89f329264bbb7db7ef99c80d83c46c440e5f62cebe4b8e374
|
4
|
+
data.tar.gz: ea7e31233c1df043a16debdf7830c6418865b73a2f109f2b6fe355f74d4794f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9573431c3894f9ad750101b6a776be465a17a7ee9a5744d5da4917c133fbdec766ce2fcc321d3592eaf27db4bdc5df9f38bd794f100a047be1aa6cf5648b0914
|
7
|
+
data.tar.gz: '0185e5bde9a8f185ac586f3eb254d8422c55435191a4ff0badae632e12be9b6f5952d35dff9639576ca725c53b2098b87281497a8bd9021034fd0643b838ad40'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
9
|
+
ruby: [2.5, 2.6, 2.7, '3.0', head]
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
17
|
+
- run: bundle exec rake
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
# 3.1.0
|
2
|
+
* Remove circular require
|
3
|
+
* Use Dry-types 1.0.0+ as coercion library
|
4
|
+
* Renamed Coercion to VirtusCoercion to support old codebases
|
5
|
+
* Replace `declarative-option` with [`trailblazer-option`](https://github.com/trailblazer/trailblazer-option)
|
6
|
+
|
7
|
+
# 3.0.4
|
8
|
+
|
9
|
+
* Add proper XML namespace support.
|
10
|
+
* [internal] Replace `XML::Binding#node_for` with function `XML::Node`.
|
11
|
+
|
12
|
+
# 3.0.3
|
13
|
+
|
14
|
+
* Replace `Uber::Option` with the new [`Declarative::Option`](https://github.com/apotonick/declarative-option). This should result in a significant performance boost.
|
15
|
+
|
16
|
+
# 3.0.2
|
17
|
+
|
18
|
+
* Initialize `Config@wrap` to avoid Ruby's warning.
|
19
|
+
* Add `#render` and `#parse` alias methods to all format modules as a generic entry point.
|
20
|
+
* In `GetValue`, use `public_send` now.
|
21
|
+
|
22
|
+
# 3.0.1
|
23
|
+
|
24
|
+
* Loosen `uber` dependency.
|
25
|
+
|
1
26
|
# 3.0.0
|
2
27
|
|
3
28
|
* Removed deprecations from 2.4.
|
data/Gemfile
CHANGED
@@ -1,19 +1,11 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
platform :rbx do
|
6
|
-
gem "psych"
|
7
|
-
gem "rubysl-irb"
|
8
|
-
gem "json_pure"
|
9
|
-
end
|
10
|
-
|
11
5
|
group :test do
|
12
|
-
gem "nokogiri", require: false
|
13
|
-
gem "multi_json", require: false
|
14
6
|
gem "minitest-line"
|
15
|
-
gem "
|
7
|
+
gem "multi_json", require: false
|
8
|
+
gem "nokogiri", require: false
|
16
9
|
end
|
10
|
+
gem 'pry-byebug'
|
17
11
|
|
18
|
-
# gem "declarative", path: "../declarative"
|
19
|
-
# gem "declarative", github: "apotonick/declarative"
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2011 -
|
1
|
+
Copyright (c) 2011 - 2021 Nick Sutterer and the roar contributors
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
Representable maps Ruby objects to documents and back.
|
4
4
|
|
5
5
|
[](https://gitter.im/trailblazer/chat)
|
6
|
+
[](http://trailblazer.to/newsletter/)
|
6
7
|
[](https://travis-ci.org/trailblazer/representable)
|
8
9
|
[](http://badge.fury.io/rb/representable)
|
9
10
|
|
10
11
|
In other words: Take an object and decorate it with a representer module. This will allow you to render a JSON, XML or YAML document from that object. But that's only half of it! You can also use representers to parse a document and create or populate an object.
|
@@ -34,8 +35,6 @@ Representations are defined using representer classes, called _decorator, or mod
|
|
34
35
|
In these examples, let's use decorators
|
35
36
|
|
36
37
|
```ruby
|
37
|
-
require 'representable/json'
|
38
|
-
|
39
38
|
class SongRepresenter < Representable::Decorator
|
40
39
|
include Representable::JSON
|
41
40
|
|
@@ -131,6 +130,7 @@ class AlbumRepresenter < Representable::Decorator
|
|
131
130
|
property :track
|
132
131
|
collection :composers
|
133
132
|
end
|
133
|
+
end
|
134
134
|
```
|
135
135
|
|
136
136
|
## More
|
@@ -142,8 +142,8 @@ Please check the [official documentation for more](http://trailblazer.to/gems/re
|
|
142
142
|
|
143
143
|
## Installation
|
144
144
|
|
145
|
-
The representable gem runs with all Ruby versions >=
|
146
|
-
|
145
|
+
The representable gem runs with all Ruby versions >= 2.4.0.
|
146
|
+
t
|
147
147
|
```ruby
|
148
148
|
gem 'representable'
|
149
149
|
```
|
@@ -169,7 +169,7 @@ gem 'nokogiri'
|
|
169
169
|
|
170
170
|
Representable started as a heavily simplified fork of the ROXML gem. Big thanks to Ben Woosley for his extremely inspiring work.
|
171
171
|
|
172
|
-
* Copyright (c) 2011-
|
172
|
+
* Copyright (c) 2011-2020 Nick Sutterer <apotonick@gmail.com>
|
173
173
|
* ROXML is Copyright (c) 2004-2009 Ben Woosley, Zak Mandhro and Anders Engstrom.
|
174
174
|
|
175
175
|
Representable is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
1
2
|
require 'bundler/setup'
|
2
3
|
require 'rake/testtask'
|
3
4
|
|
@@ -9,9 +10,3 @@ Rake::TestTask.new(:test) do |test|
|
|
9
10
|
test.test_files = FileList['test/**/*_test.rb']
|
10
11
|
test.verbose = true
|
11
12
|
end
|
12
|
-
|
13
|
-
Rake::TestTask.new(:dtest) do |test|
|
14
|
-
test.libs << 'test-with-deprecations'
|
15
|
-
test.test_files = FileList['test-with-deprecations/**/*_test.rb']
|
16
|
-
test.verbose = true
|
17
|
-
end
|
data/TODO
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
* Pass key/index as first block arg to :class and :extend
|
2
2
|
class: |key, hsh|
|
3
3
|
|
4
|
-
* Allow passing options to Binding#serialize.
|
5
|
-
serialize(.., options{:exclude => ..})
|
6
4
|
|
7
5
|
document `XML::AttributeHash` etc
|
8
6
|
|
@@ -37,4 +35,4 @@ module ReaderWriter
|
|
37
35
|
* DISCUSS: should inline representers be created at runtime, so we don't need ::representer_engine?
|
38
36
|
* deprecate `Decorator::Coercion`.
|
39
37
|
|
40
|
-
* cleanup XML so it matches the current #serialize standard.
|
38
|
+
* cleanup XML so it matches the current #serialize standard.
|
data/TODO-4.0.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Decorator
|
2
|
+
|
3
|
+
XML::Binding::Collection.to_xml(represented)
|
4
|
+
bindings.each bin.to_xml
|
5
|
+
|
6
|
+
|
7
|
+
# hat vorteil: [].each{ Collection.to_xml(item) }
|
8
|
+
|
9
|
+
* make all properties "Object-like", even arrays of strings etc. This saves us from having `extend ObjectBinding if typed?` and we could just call to_hash/from_hash on all attributes. performance issues here? otherwise: implement!
|
10
|
+
|
11
|
+
|
12
|
+
# how to?
|
13
|
+
|
14
|
+
class CH
|
15
|
+
wrap :character
|
16
|
+
prpoerty :a
|
17
|
+
|
18
|
+
|
19
|
+
class
|
20
|
+
proerty :author, dec: CH
|
21
|
+
|
22
|
+
# how to?
|
23
|
+
|
24
|
+
* override specific bindings and their logic? e.g. `Namespace#read`
|
25
|
+
* Extend nested representers, e.g. the namespace prefix, when it gets plugged into composition
|
26
|
+
* Easier polymorphic representer
|
27
|
+
|
28
|
+
# XML
|
29
|
+
|
30
|
+
* ditch annoying nokogiri in favor of https://github.com/YorickPeterse/oga
|
31
|
+
|
32
|
+
# Parsing
|
33
|
+
|
34
|
+
* Let bindings have any "xpath"
|
35
|
+
* Allow to parse "wildcard" sections where you have no idea about the property names (and attribute names, eg. with links)
|
36
|
+
|
37
|
+
# Options
|
38
|
+
|
39
|
+
* There should be an easier way to pass a set of options to all nested #to_node decorators.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
representable_attrs.keys.each do |property|
|
43
|
+
options[property.to_sym] = { show_definition: false, namespaces: options[:namespaces] }
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
* Allow passing options to Binding#serialize.
|
48
|
+
serialize(.., options{:exclude => ..})
|
49
|
+
|
50
|
+
|
51
|
+
# wrap, as
|
52
|
+
|
53
|
+
AsWithNamespace( Binding )
|
54
|
+
BUT NOT FOR AsWithNamespace( Binding::Attribute )
|
55
|
+
=> selectively wrap bindings at compile- and runtime
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
* Cleanup the manifest part in Decorator.
|
63
|
+
|
64
|
+
* all property objects should be extended/wrapped so we don't need the switch.
|
65
|
+
|
66
|
+
# Deprecations
|
67
|
+
|
68
|
+
* deprecate instance: { nil } which is superseded by parse_strategy: :sync
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
from_hash, property :band, class: vergessen
|
data/lib/representable.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "uber/delegates"
|
2
|
-
|
2
|
+
require "uber/callable"
|
3
3
|
require "declarative/schema"
|
4
4
|
|
5
|
+
require "representable/option"
|
5
6
|
require "representable/config"
|
6
7
|
require "representable/definition"
|
7
8
|
require "representable/declarative"
|
@@ -15,6 +16,17 @@ require "representable/for_collection"
|
|
15
16
|
require "representable/represent"
|
16
17
|
|
17
18
|
module Representable
|
19
|
+
autoload :Binding, 'representable/binding'
|
20
|
+
autoload :HashMethods, 'representable/hash_methods'
|
21
|
+
autoload :Decorator, 'representable/decorator'
|
22
|
+
|
23
|
+
autoload :Hash, 'representable/hash'
|
24
|
+
autoload :JSON, 'representable/json'
|
25
|
+
autoload :Object, 'representable/object'
|
26
|
+
autoload :YAML, 'representable/yaml'
|
27
|
+
autoload :XML, 'representable/xml'
|
28
|
+
|
29
|
+
|
18
30
|
attr_writer :representable_attrs
|
19
31
|
|
20
32
|
def self.included(base)
|
@@ -31,7 +43,7 @@ module Representable
|
|
31
43
|
private
|
32
44
|
# Reads values from +doc+ and sets properties accordingly.
|
33
45
|
def update_properties_from(doc, options, format)
|
34
|
-
propagated_options = normalize_options(options)
|
46
|
+
propagated_options = normalize_options(**options)
|
35
47
|
|
36
48
|
representable_map!(doc, propagated_options, format, :uncompile_fragment)
|
37
49
|
represented
|
@@ -39,25 +51,12 @@ private
|
|
39
51
|
|
40
52
|
# Compiles the document going through all properties.
|
41
53
|
def create_representation_with(doc, options, format)
|
42
|
-
propagated_options = normalize_options(options)
|
54
|
+
propagated_options = normalize_options(**options)
|
43
55
|
|
44
56
|
representable_map!(doc, propagated_options, format, :compile_fragment)
|
45
57
|
doc
|
46
58
|
end
|
47
59
|
|
48
|
-
class Binding::Map < Array
|
49
|
-
def call(method, options)
|
50
|
-
each do |bin|
|
51
|
-
options[:binding] = bin # this is so much faster than options.merge().
|
52
|
-
bin.send(method, options)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# TODO: Merge with Definitions.
|
57
|
-
def <<(binding) # can be slow. this is compile time code.
|
58
|
-
(existing = find { |bin| bin.name == binding.name }) ? self[index(existing)] = binding : super(binding)
|
59
|
-
end
|
60
|
-
end
|
61
60
|
|
62
61
|
def representable_map(options, format)
|
63
62
|
Binding::Map.new(representable_bindings_for(format, options))
|
@@ -73,9 +72,8 @@ private
|
|
73
72
|
representable_attrs.collect {|definition| format.build(definition) }
|
74
73
|
end
|
75
74
|
|
76
|
-
def normalize_options(options)
|
77
|
-
|
78
|
-
{user_options: {}}.merge(options) # TODO: use keyword args once we drop 2.0.
|
75
|
+
def normalize_options(user_options: {}, **options)
|
76
|
+
{ user_options: user_options }.merge(options)
|
79
77
|
end
|
80
78
|
|
81
79
|
# Prepares options for a particular nested representer.
|
@@ -95,8 +93,8 @@ private
|
|
95
93
|
@representable_attrs ||= self.class.definitions
|
96
94
|
end
|
97
95
|
|
98
|
-
def representation_wrap(
|
99
|
-
representable_attrs.wrap_for(represented,
|
96
|
+
def representation_wrap(options = {})
|
97
|
+
representable_attrs.wrap_for(represented, options)
|
100
98
|
end
|
101
99
|
|
102
100
|
def represented
|
@@ -117,8 +115,4 @@ private
|
|
117
115
|
represented.extend(self)
|
118
116
|
end
|
119
117
|
end
|
120
|
-
|
121
|
-
# require "representable/deprecations"
|
122
118
|
end
|
123
|
-
|
124
|
-
require 'representable/autoload'
|
@@ -1,8 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uber/delegates'
|
4
|
+
|
1
5
|
module Representable
|
2
6
|
# The Binding provides methods to read/write the fragment for one property.
|
3
7
|
#
|
4
8
|
# Actually parsing the fragment from the document happens in Binding#read, everything after that is generic.
|
5
9
|
class Binding
|
10
|
+
class Map < Array
|
11
|
+
def call(method, options)
|
12
|
+
each do |bin|
|
13
|
+
options[:binding] = bin # this is so much faster than options.merge().
|
14
|
+
bin.send(method, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: Merge with Definitions.
|
19
|
+
def <<(binding) # can be slow. this is compile time code.
|
20
|
+
(existing = find { |bin| bin.name == binding.name }) ? self[index(existing)] = binding : super(binding)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
6
24
|
class FragmentNotFound
|
7
25
|
end
|
8
26
|
|
@@ -29,12 +47,12 @@ module Representable
|
|
29
47
|
module Deprecatable
|
30
48
|
# Retrieve value and write fragment to the doc.
|
31
49
|
def compile_fragment(options)
|
32
|
-
render_pipeline(nil, options).(nil, options)
|
50
|
+
render_pipeline(nil, options).call(nil, options)
|
33
51
|
end
|
34
52
|
|
35
53
|
# Parse value from doc and update the model property.
|
36
54
|
def uncompile_fragment(options)
|
37
|
-
parse_pipeline(options[:doc], options).(options[:doc], options)
|
55
|
+
parse_pipeline(options[:doc], options).call(options[:doc], options)
|
38
56
|
end
|
39
57
|
end
|
40
58
|
include Deprecatable
|
@@ -43,7 +61,7 @@ module Representable
|
|
43
61
|
def evaluate_option(name, input, options)
|
44
62
|
proc = self[name]
|
45
63
|
# puts "@@@@@ #{self.inspect}, #{name}...... #{self[name]}"
|
46
|
-
proc.(send(:exec_context, options), options.merge(user_options: options[:options][:user_options], input: input)) # from Uber::Options::Value. # NOTE: this can also be the Proc object if it's not wrapped by Uber:::Value.
|
64
|
+
proc.call(exec_context: send(:exec_context, options), keyword_arguments: options.merge(user_options: options[:options][:user_options], input: input)) # from Uber::Options::Value. # NOTE: this can also be the Proc object if it's not wrapped by Uber:::Value.
|
47
65
|
end
|
48
66
|
end
|
49
67
|
include EvaluateOption
|
@@ -53,29 +71,30 @@ module Representable
|
|
53
71
|
end
|
54
72
|
|
55
73
|
def skipable_empty_value?(value)
|
56
|
-
value.nil? and
|
74
|
+
value.nil? and !(self[:render_nil])
|
57
75
|
end
|
58
76
|
|
59
77
|
def default_for(value)
|
60
78
|
return self[:default] if skipable_empty_value?(value)
|
79
|
+
|
61
80
|
value
|
62
81
|
end
|
63
82
|
|
64
83
|
attr_accessor :cached_representer
|
65
84
|
|
66
|
-
require
|
85
|
+
require 'representable/pipeline_factories'
|
67
86
|
include Factories
|
68
87
|
|
69
|
-
|
88
|
+
private
|
70
89
|
|
71
90
|
def setup_exec_context!
|
72
|
-
@exec_context = ->(options) { options[:represented] }
|
73
|
-
@exec_context = ->(
|
74
|
-
@exec_context = ->(options) { options[:decorator] }
|
91
|
+
@exec_context = ->(options) { options[:represented] } unless self[:exec_context]
|
92
|
+
@exec_context = ->(_options) { self } if self[:exec_context] == :binding
|
93
|
+
@exec_context = ->(options) { options[:decorator] } if self[:exec_context] == :decorator
|
75
94
|
end
|
76
95
|
|
77
96
|
def exec_context(options)
|
78
|
-
@exec_context.(options)
|
97
|
+
@exec_context.call(options)
|
79
98
|
end
|
80
99
|
|
81
100
|
def parse_pipeline(input, options)
|
@@ -90,8 +109,9 @@ module Representable
|
|
90
109
|
module Collection
|
91
110
|
def skipable_empty_value?(value)
|
92
111
|
# TODO: this can be optimized, again.
|
93
|
-
return true if value.nil?
|
94
|
-
|
112
|
+
return true if value.nil? && !(self[:render_nil]) # FIXME: test this without the "and"
|
113
|
+
|
114
|
+
true if (self[:render_empty] == false) && value && value.empty? # TODO: change in 2.0, don't render emtpy.
|
95
115
|
end
|
96
116
|
end
|
97
117
|
end
|
data/lib/representable/cached.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
gem 'dry-types', '>= 1.0.0'
|
2
|
+
require "dry-types"
|
2
3
|
|
3
4
|
module Representable
|
4
5
|
module Coercion
|
6
|
+
module Types
|
7
|
+
include Dry::Types()
|
8
|
+
end
|
5
9
|
class Coercer
|
6
10
|
def initialize(type)
|
7
11
|
@type = type
|
8
12
|
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
def call(input, options)
|
13
|
-
Virtus::Attribute.build(@type).coerce(input)
|
14
|
+
def call(input, _options)
|
15
|
+
@type.call(input)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -34,4 +36,4 @@ module Representable
|
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
37
|
-
end
|
39
|
+
end
|