representable 2.0.0.rc2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -0
- data/lib/representable/declarative.rb +11 -3
- data/lib/representable/version.rb +1 -1
- metadata +28 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c087dd37e5b99234457b7af5b0982c4238f1059e
|
4
|
+
data.tar.gz: 36e96f16f6a45cd22d5b1e281e0883027cd18c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2712084960fe0e91579c9bd7a11a33c8ad1ad1512517810ee05b751b5d8dccc302fec8eb195b39b18c0283e62de3285dc972f15f4f9a2c6073f89829f3b8780b
|
7
|
+
data.tar.gz: 7de91a94a2264f81010610094d1ab81657dc4c4ac0376393e3bb6e717b9f844dd189ca921a6d397384f490253858e21e419931632f47cc074f48cd9580b38783
|
data/README.md
CHANGED
@@ -527,6 +527,8 @@ Here's a list of all dynamic options and their argument signature.
|
|
527
527
|
* `instance: lambda { |fragment, [i], args| }` ([see Object Creation](#polymorphic-object-creation))
|
528
528
|
* `reader: lambda { |document, args| }` ([see Read And Write](#overriding-read-and-write))
|
529
529
|
* `writer: lambda { |document, args| }` ([see Read And Write](#overriding-read-and-write))
|
530
|
+
* `parse_filter: lambda { |fragment, document, args| }` ([see Filters](#filters)))
|
531
|
+
* `render_filter: lambda { |value, document, args| }` ([see Filters](#filters))
|
530
532
|
* `if: lambda { |args| }` ([see Conditions](#conditions))
|
531
533
|
* `prepare: lambda { |object, args| }` ([see docs](#rendering-and-parsing-without-extend))
|
532
534
|
* `serialize: lambda { |object, args| }` ([see docs](#overriding-serialize-and-deserialize))
|
@@ -550,6 +552,48 @@ The `Options` instance exposes the following readers: `#binding`, `#represented`
|
|
550
552
|
Option-specific arguments (e.g. `fragment`, [see here](#available-options)) are still prepended, making the `Options` object always the *last* argument.
|
551
553
|
|
552
554
|
|
555
|
+
## Filters
|
556
|
+
|
557
|
+
Representabe offers you `:render_filter` and `:parse_filter` to modify the value to be rendered or parsed.
|
558
|
+
|
559
|
+
Filters are implemented using `Pipeline`, which means you can add as many as you want. The result from the former filter will be passed to the next.
|
560
|
+
|
561
|
+
```ruby
|
562
|
+
property :title, render_filter: lambda { |value, doc, *args| value.html_safe }
|
563
|
+
```
|
564
|
+
|
565
|
+
This will be executed right before the fragment gets rendered into the document.
|
566
|
+
|
567
|
+
```ruby
|
568
|
+
property :title, parse_filter: lambda { |fragment, doc, *args| Sanitizer.call(fragment) }
|
569
|
+
```
|
570
|
+
|
571
|
+
Just before setting the fragment to the object via the `:setter`, the `:parse_filter` is called.
|
572
|
+
|
573
|
+
|
574
|
+
## Callable Options
|
575
|
+
|
576
|
+
While lambdas are one option for dynamic options, you might also pass a "callable" object to a directive.
|
577
|
+
|
578
|
+
```ruby
|
579
|
+
class Sanitizer
|
580
|
+
include Uber::Callable
|
581
|
+
|
582
|
+
def call(represented, fragment, doc, *args)
|
583
|
+
fragment.sanitize
|
584
|
+
end
|
585
|
+
end
|
586
|
+
```
|
587
|
+
|
588
|
+
Note how including `Uber::Callable` marks instances of this class as callable. No `respond_to?` or other magic takes place here.
|
589
|
+
|
590
|
+
```ruby
|
591
|
+
property :title, parse_filter: Santizer.new
|
592
|
+
```
|
593
|
+
|
594
|
+
This is enough to have the `Sanitizer` class run with all the arguments that are usually passed to the lambda (preceded by the represented object as first argument).
|
595
|
+
|
596
|
+
|
553
597
|
## XML Support
|
554
598
|
|
555
599
|
While representable does a great job with JSON, it also features support for XML, YAML and pure ruby hashes.
|
@@ -49,10 +49,18 @@ module Representable
|
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
52
|
-
#
|
52
|
+
# This method is meant to be overridden if you want to add or change DSL options.
|
53
|
+
# The options hash is already initialized, add or change elements as you need.
|
54
|
+
#
|
55
|
+
# Example:
|
56
|
+
#
|
57
|
+
# def build_definition(name, options, &block)
|
58
|
+
# options[:pass_options] = true
|
59
|
+
# options[:render_filter] << Sanitizer.new if options[:sanitize]
|
60
|
+
# options[:setter] << lambda { |fragment, options| send("set_#{options.binding.name}=", fragment) }
|
61
|
+
# super # don't forget to call super
|
62
|
+
# end
|
53
63
|
def build_definition(name, options, &block)
|
54
|
-
# change options[..]= here.
|
55
|
-
|
56
64
|
base = nil
|
57
65
|
|
58
66
|
if options[:inherit] # TODO: move this to Definition.
|
metadata
CHANGED
@@ -1,153 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: representable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: uber
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.0.7
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.0.7
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: test_xml
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.1.6
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.1.6
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: minitest
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 5.0.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 5.0.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: mocha
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 0.13.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.13.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: mongoid
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: virtus
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: json
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ~>
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: 1.7.7
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ~>
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 1.7.7
|
153
153
|
description: Renders and parses JSON/XML/YAML documents from and to Ruby objects.
|
@@ -158,8 +158,8 @@ executables: []
|
|
158
158
|
extensions: []
|
159
159
|
extra_rdoc_files: []
|
160
160
|
files:
|
161
|
-
-
|
162
|
-
-
|
161
|
+
- .gitignore
|
162
|
+
- .travis.yml
|
163
163
|
- CHANGES.md
|
164
164
|
- Gemfile
|
165
165
|
- LICENSE
|
@@ -250,14 +250,14 @@ require_paths:
|
|
250
250
|
- lib
|
251
251
|
required_ruby_version: !ruby/object:Gem::Requirement
|
252
252
|
requirements:
|
253
|
-
- -
|
253
|
+
- - '>='
|
254
254
|
- !ruby/object:Gem::Version
|
255
255
|
version: '0'
|
256
256
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
257
|
requirements:
|
258
|
-
- -
|
258
|
+
- - '>='
|
259
259
|
- !ruby/object:Gem::Version
|
260
|
-
version:
|
260
|
+
version: '0'
|
261
261
|
requirements: []
|
262
262
|
rubyforge_project:
|
263
263
|
rubygems_version: 2.2.2
|
@@ -265,46 +265,4 @@ signing_key:
|
|
265
265
|
specification_version: 4
|
266
266
|
summary: Renders and parses JSON/XML/YAML documents from and to Ruby objects. Includes
|
267
267
|
plain properties, collections, nesting, coercion and more.
|
268
|
-
test_files:
|
269
|
-
- test/as_test.rb
|
270
|
-
- test/class_test.rb
|
271
|
-
- test/coercion_test.rb
|
272
|
-
- test/config/inherit_test.rb
|
273
|
-
- test/config_test.rb
|
274
|
-
- test/decorator_scope_test.rb
|
275
|
-
- test/decorator_test.rb
|
276
|
-
- test/definition_test.rb
|
277
|
-
- test/example.rb
|
278
|
-
- test/exec_context_test.rb
|
279
|
-
- test/features_test.rb
|
280
|
-
- test/filter_test.rb
|
281
|
-
- test/for_collection_test.rb
|
282
|
-
- test/generic_test.rb
|
283
|
-
- test/getter_setter_test.rb
|
284
|
-
- test/hash_bindings_test.rb
|
285
|
-
- test/hash_test.rb
|
286
|
-
- test/if_test.rb
|
287
|
-
- test/inherit_test.rb
|
288
|
-
- test/inheritable_test.rb
|
289
|
-
- test/inline_test.rb
|
290
|
-
- test/instance_test.rb
|
291
|
-
- test/is_representable_test.rb
|
292
|
-
- test/json_test.rb
|
293
|
-
- test/lonely_test.rb
|
294
|
-
- test/mongoid_test.rb
|
295
|
-
- test/nested_test.rb
|
296
|
-
- test/parse_strategy_test.rb
|
297
|
-
- test/pass_options_test.rb
|
298
|
-
- test/prepare_test.rb
|
299
|
-
- test/reader_writer_test.rb
|
300
|
-
- test/represent_test.rb
|
301
|
-
- test/representable_test.rb
|
302
|
-
- test/schema_test.rb
|
303
|
-
- test/serialize_deserialize_test.rb
|
304
|
-
- test/stringify_hash_test.rb
|
305
|
-
- test/test_helper.rb
|
306
|
-
- test/test_helper_test.rb
|
307
|
-
- test/wrap_test.rb
|
308
|
-
- test/xml_bindings_test.rb
|
309
|
-
- test/xml_test.rb
|
310
|
-
- test/yaml_test.rb
|
268
|
+
test_files: []
|