yaks-html 0.6.0.alpha → 0.6.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -525
- data/Rakefile +1 -41
- data/{yaks-html/lib → lib}/yaks-html.rb +0 -0
- data/{yaks-html/lib → lib}/yaks/format/html.rb +0 -0
- data/{yaks-html/lib → lib}/yaks/format/template.html +0 -0
- data/{yaks-html/spec → spec}/spec_helper.rb +0 -0
- data/{yaks-html/yaks-html.gemspec → yaks-html.gemspec} +1 -1
- metadata +11 -108
- data/.gitignore +0 -7
- data/.travis.yml +0 -36
- data/ADDING_FORMATS.md +0 -13
- data/CHANGELOG.md +0 -149
- data/Gemfile +0 -4
- data/IDENTIFIERS.md +0 -113
- data/LICENSE +0 -7
- data/bench/bench.rb +0 -16
- data/bench/bench_1000.rb +0 -60
- data/notes.org +0 -72
- data/shaved_yak.gif +0 -0
- data/yaks-html/README.md +0 -3
- data/yaks/README.md +0 -526
- data/yaks/lib/yaks.rb +0 -62
- data/yaks/lib/yaks/breaking_changes.rb +0 -49
- data/yaks/lib/yaks/collection_mapper.rb +0 -52
- data/yaks/lib/yaks/collection_resource.rb +0 -73
- data/yaks/lib/yaks/config.rb +0 -65
- data/yaks/lib/yaks/config/dsl.rb +0 -165
- data/yaks/lib/yaks/default_policy.rb +0 -100
- data/yaks/lib/yaks/format.rb +0 -87
- data/yaks/lib/yaks/format/collection_json.rb +0 -42
- data/yaks/lib/yaks/format/hal.rb +0 -82
- data/yaks/lib/yaks/format/json_api.rb +0 -86
- data/yaks/lib/yaks/fp.rb +0 -26
- data/yaks/lib/yaks/fp/callable.rb +0 -9
- data/yaks/lib/yaks/fp/hash_updatable.rb +0 -19
- data/yaks/lib/yaks/fp/updatable.rb +0 -17
- data/yaks/lib/yaks/mapper.rb +0 -75
- data/yaks/lib/yaks/mapper/association.rb +0 -43
- data/yaks/lib/yaks/mapper/association_mapper.rb +0 -42
- data/yaks/lib/yaks/mapper/attribute.rb +0 -17
- data/yaks/lib/yaks/mapper/class_methods.rb +0 -37
- data/yaks/lib/yaks/mapper/config.rb +0 -44
- data/yaks/lib/yaks/mapper/has_many.rb +0 -29
- data/yaks/lib/yaks/mapper/has_one.rb +0 -15
- data/yaks/lib/yaks/mapper/link.rb +0 -91
- data/yaks/lib/yaks/null_resource.rb +0 -40
- data/yaks/lib/yaks/primitivize.rb +0 -45
- data/yaks/lib/yaks/resource.rb +0 -51
- data/yaks/lib/yaks/resource/link.rb +0 -21
- data/yaks/lib/yaks/runner.rb +0 -101
- data/yaks/lib/yaks/util.rb +0 -56
- data/yaks/lib/yaks/version.rb +0 -3
- data/yaks/spec/acceptance/acceptance_spec.rb +0 -48
- data/yaks/spec/acceptance/json_shared_examples.rb +0 -8
- data/yaks/spec/acceptance/models.rb +0 -48
- data/yaks/spec/fixture_helpers.rb +0 -14
- data/yaks/spec/integration/map_to_resource_spec.rb +0 -28
- data/yaks/spec/json/confucius.collection.json +0 -28
- data/yaks/spec/json/confucius.hal.json +0 -59
- data/yaks/spec/json/confucius.json_api.json +0 -51
- data/yaks/spec/json/john.hal.json +0 -29
- data/yaks/spec/json/plant_collection.collection.json +0 -32
- data/yaks/spec/json/plant_collection.hal.json +0 -34
- data/yaks/spec/json/youtypeitwepostit.collection.json +0 -45
- data/yaks/spec/spec_helper.rb +0 -30
- data/yaks/spec/support/classes_for_policy_testing.rb +0 -36
- data/yaks/spec/support/deep_eql.rb +0 -123
- data/yaks/spec/support/fixtures.rb +0 -6
- data/yaks/spec/support/friends_mapper.rb +0 -29
- data/yaks/spec/support/models.rb +0 -23
- data/yaks/spec/support/pet_mapper.rb +0 -3
- data/yaks/spec/support/pet_peeve_mapper.rb +0 -3
- data/yaks/spec/support/shared_contexts.rb +0 -57
- data/yaks/spec/support/youtypeit_models_mappers.rb +0 -20
- data/yaks/spec/unit/yaks/collection_mapper_spec.rb +0 -165
- data/yaks/spec/unit/yaks/collection_resource_spec.rb +0 -77
- data/yaks/spec/unit/yaks/config/dsl_spec.rb +0 -87
- data/yaks/spec/unit/yaks/config_spec.rb +0 -74
- data/yaks/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +0 -80
- data/yaks/spec/unit/yaks/default_policy_spec.rb +0 -70
- data/yaks/spec/unit/yaks/format/collection_json_spec.rb +0 -41
- data/yaks/spec/unit/yaks/format/hal_spec.rb +0 -44
- data/yaks/spec/unit/yaks/format/json_api_spec.rb +0 -42
- data/yaks/spec/unit/yaks/format_spec.rb +0 -37
- data/yaks/spec/unit/yaks/fp/callable_spec.rb +0 -13
- data/yaks/spec/unit/yaks/fp/hash_updatable_spec.rb +0 -22
- data/yaks/spec/unit/yaks/fp/updatable_spec.rb +0 -22
- data/yaks/spec/unit/yaks/fp_spec.rb +0 -31
- data/yaks/spec/unit/yaks/mapper/association_mapper_spec.rb +0 -60
- data/yaks/spec/unit/yaks/mapper/association_spec.rb +0 -135
- data/yaks/spec/unit/yaks/mapper/attribute_spec.rb +0 -20
- data/yaks/spec/unit/yaks/mapper/class_methods_spec.rb +0 -67
- data/yaks/spec/unit/yaks/mapper/config_spec.rb +0 -166
- data/yaks/spec/unit/yaks/mapper/has_many_spec.rb +0 -89
- data/yaks/spec/unit/yaks/mapper/has_one_spec.rb +0 -51
- data/yaks/spec/unit/yaks/mapper/link_spec.rb +0 -196
- data/yaks/spec/unit/yaks/mapper_spec.rb +0 -303
- data/yaks/spec/unit/yaks/null_resource_spec.rb +0 -32
- data/yaks/spec/unit/yaks/primitivize_spec.rb +0 -77
- data/yaks/spec/unit/yaks/resource/link_spec.rb +0 -20
- data/yaks/spec/unit/yaks/resource_spec.rb +0 -108
- data/yaks/spec/unit/yaks/runner_spec.rb +0 -260
- data/yaks/spec/unit/yaks/util_spec.rb +0 -49
- data/yaks/spec/yaml/confucius.yaml +0 -28
- data/yaks/spec/yaml/youtypeitwepostit.yaml +0 -9
- data/yaks/yaks.gemspec +0 -41
data/Rakefile
CHANGED
@@ -1,43 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'yaks-html'
|
3
|
-
require 'mutant'
|
4
|
-
require 'rubygems/package_task'
|
5
|
-
require 'rspec/core/rake_task'
|
6
|
-
require 'yard'
|
1
|
+
load '../rakelib/shared.rake'
|
7
2
|
|
8
|
-
desc "Push gem to rubygems.org"
|
9
|
-
task :push => ["yaks:gem", "yaks-html:gem"] do
|
10
|
-
sh "git tag v#{Yaks::VERSION}"
|
11
|
-
sh "git push --tags"
|
12
|
-
sh "gem push pkg/yaks-#{Yaks::VERSION}.gem"
|
13
|
-
sh "gem push pkg/yaks-html-#{Yaks::VERSION}.gem"
|
14
|
-
end
|
15
|
-
|
16
|
-
def gem_tasks(gem)
|
17
|
-
namespace gem do
|
18
|
-
spec = Gem::Specification.load("#{gem}/#{gem}.gemspec")
|
19
|
-
Gem::PackageTask.new(spec).define
|
20
|
-
|
21
|
-
task :mutant do
|
22
|
-
pattern = ENV.fetch('PATTERN', gem == :yaks ? 'Yaks*' : 'Yaks::Format::HTML*')
|
23
|
-
opts = ENV.fetch('MUTANT_OPTS', '').split(' ')
|
24
|
-
Dir.chdir gem.to_s do
|
25
|
-
result = Mutant::CLI.run(%W[-Ilib -ryaks --use rspec --score 100] + opts + [pattern])
|
26
|
-
fail unless result == Mutant::CLI::EXIT_SUCCESS
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
RSpec::Core::RakeTask.new(:rspec) do |t, task_args|
|
31
|
-
t.rspec_opts = "-I#{gem}/spec #{gem}/spec"
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
YARD::Rake::YardocTask.new do |t|
|
36
|
-
t.files = ["#{gem}/lib/**/*.rb" "#{gem}/**/*.md"]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
gem_tasks(:yaks)
|
43
3
|
gem_tasks(:"yaks-html")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
|
15
15
|
gem.require_paths = %w[lib]
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
|
-
gem.test_files =
|
17
|
+
gem.test_files = gem.files.grep(/^spec/)
|
18
18
|
gem.extra_rdoc_files = %w[README.md]
|
19
19
|
|
20
20
|
gem.add_runtime_dependency 'yaks', Yaks::VERSION
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaks-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.0.alpha
|
4
|
+
version: 0.6.0.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Brasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaks
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.6.0.alpha
|
19
|
+
version: 0.6.0.alpha.1
|
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
|
-
version: 0.6.0.alpha
|
26
|
+
version: 0.6.0.alpha.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hexp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,111 +46,13 @@ extensions: []
|
|
46
46
|
extra_rdoc_files:
|
47
47
|
- README.md
|
48
48
|
files:
|
49
|
-
- ".gitignore"
|
50
|
-
- ".travis.yml"
|
51
|
-
- ADDING_FORMATS.md
|
52
|
-
- CHANGELOG.md
|
53
|
-
- Gemfile
|
54
|
-
- IDENTIFIERS.md
|
55
|
-
- LICENSE
|
56
49
|
- README.md
|
57
50
|
- Rakefile
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
- yaks-html
|
63
|
-
- yaks-html/lib/yaks-html.rb
|
64
|
-
- yaks-html/lib/yaks/format/html.rb
|
65
|
-
- yaks-html/lib/yaks/format/template.html
|
66
|
-
- yaks-html/spec/spec_helper.rb
|
67
|
-
- yaks-html/yaks-html.gemspec
|
68
|
-
- yaks/README.md
|
69
|
-
- yaks/lib/yaks.rb
|
70
|
-
- yaks/lib/yaks/breaking_changes.rb
|
71
|
-
- yaks/lib/yaks/collection_mapper.rb
|
72
|
-
- yaks/lib/yaks/collection_resource.rb
|
73
|
-
- yaks/lib/yaks/config.rb
|
74
|
-
- yaks/lib/yaks/config/dsl.rb
|
75
|
-
- yaks/lib/yaks/default_policy.rb
|
76
|
-
- yaks/lib/yaks/format.rb
|
77
|
-
- yaks/lib/yaks/format/collection_json.rb
|
78
|
-
- yaks/lib/yaks/format/hal.rb
|
79
|
-
- yaks/lib/yaks/format/json_api.rb
|
80
|
-
- yaks/lib/yaks/fp.rb
|
81
|
-
- yaks/lib/yaks/fp/callable.rb
|
82
|
-
- yaks/lib/yaks/fp/hash_updatable.rb
|
83
|
-
- yaks/lib/yaks/fp/updatable.rb
|
84
|
-
- yaks/lib/yaks/mapper.rb
|
85
|
-
- yaks/lib/yaks/mapper/association.rb
|
86
|
-
- yaks/lib/yaks/mapper/association_mapper.rb
|
87
|
-
- yaks/lib/yaks/mapper/attribute.rb
|
88
|
-
- yaks/lib/yaks/mapper/class_methods.rb
|
89
|
-
- yaks/lib/yaks/mapper/config.rb
|
90
|
-
- yaks/lib/yaks/mapper/has_many.rb
|
91
|
-
- yaks/lib/yaks/mapper/has_one.rb
|
92
|
-
- yaks/lib/yaks/mapper/link.rb
|
93
|
-
- yaks/lib/yaks/null_resource.rb
|
94
|
-
- yaks/lib/yaks/primitivize.rb
|
95
|
-
- yaks/lib/yaks/resource.rb
|
96
|
-
- yaks/lib/yaks/resource/link.rb
|
97
|
-
- yaks/lib/yaks/runner.rb
|
98
|
-
- yaks/lib/yaks/util.rb
|
99
|
-
- yaks/lib/yaks/version.rb
|
100
|
-
- yaks/spec/acceptance/acceptance_spec.rb
|
101
|
-
- yaks/spec/acceptance/json_shared_examples.rb
|
102
|
-
- yaks/spec/acceptance/models.rb
|
103
|
-
- yaks/spec/fixture_helpers.rb
|
104
|
-
- yaks/spec/integration/map_to_resource_spec.rb
|
105
|
-
- yaks/spec/json/confucius.collection.json
|
106
|
-
- yaks/spec/json/confucius.hal.json
|
107
|
-
- yaks/spec/json/confucius.json_api.json
|
108
|
-
- yaks/spec/json/john.hal.json
|
109
|
-
- yaks/spec/json/plant_collection.collection.json
|
110
|
-
- yaks/spec/json/plant_collection.hal.json
|
111
|
-
- yaks/spec/json/youtypeitwepostit.collection.json
|
112
|
-
- yaks/spec/spec_helper.rb
|
113
|
-
- yaks/spec/support/classes_for_policy_testing.rb
|
114
|
-
- yaks/spec/support/deep_eql.rb
|
115
|
-
- yaks/spec/support/fixtures.rb
|
116
|
-
- yaks/spec/support/friends_mapper.rb
|
117
|
-
- yaks/spec/support/models.rb
|
118
|
-
- yaks/spec/support/pet_mapper.rb
|
119
|
-
- yaks/spec/support/pet_peeve_mapper.rb
|
120
|
-
- yaks/spec/support/shared_contexts.rb
|
121
|
-
- yaks/spec/support/youtypeit_models_mappers.rb
|
122
|
-
- yaks/spec/unit/yaks/collection_mapper_spec.rb
|
123
|
-
- yaks/spec/unit/yaks/collection_resource_spec.rb
|
124
|
-
- yaks/spec/unit/yaks/config/dsl_spec.rb
|
125
|
-
- yaks/spec/unit/yaks/config_spec.rb
|
126
|
-
- yaks/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb
|
127
|
-
- yaks/spec/unit/yaks/default_policy_spec.rb
|
128
|
-
- yaks/spec/unit/yaks/format/collection_json_spec.rb
|
129
|
-
- yaks/spec/unit/yaks/format/hal_spec.rb
|
130
|
-
- yaks/spec/unit/yaks/format/json_api_spec.rb
|
131
|
-
- yaks/spec/unit/yaks/format_spec.rb
|
132
|
-
- yaks/spec/unit/yaks/fp/callable_spec.rb
|
133
|
-
- yaks/spec/unit/yaks/fp/hash_updatable_spec.rb
|
134
|
-
- yaks/spec/unit/yaks/fp/updatable_spec.rb
|
135
|
-
- yaks/spec/unit/yaks/fp_spec.rb
|
136
|
-
- yaks/spec/unit/yaks/mapper/association_mapper_spec.rb
|
137
|
-
- yaks/spec/unit/yaks/mapper/association_spec.rb
|
138
|
-
- yaks/spec/unit/yaks/mapper/attribute_spec.rb
|
139
|
-
- yaks/spec/unit/yaks/mapper/class_methods_spec.rb
|
140
|
-
- yaks/spec/unit/yaks/mapper/config_spec.rb
|
141
|
-
- yaks/spec/unit/yaks/mapper/has_many_spec.rb
|
142
|
-
- yaks/spec/unit/yaks/mapper/has_one_spec.rb
|
143
|
-
- yaks/spec/unit/yaks/mapper/link_spec.rb
|
144
|
-
- yaks/spec/unit/yaks/mapper_spec.rb
|
145
|
-
- yaks/spec/unit/yaks/null_resource_spec.rb
|
146
|
-
- yaks/spec/unit/yaks/primitivize_spec.rb
|
147
|
-
- yaks/spec/unit/yaks/resource/link_spec.rb
|
148
|
-
- yaks/spec/unit/yaks/resource_spec.rb
|
149
|
-
- yaks/spec/unit/yaks/runner_spec.rb
|
150
|
-
- yaks/spec/unit/yaks/util_spec.rb
|
151
|
-
- yaks/spec/yaml/confucius.yaml
|
152
|
-
- yaks/spec/yaml/youtypeitwepostit.yaml
|
153
|
-
- yaks/yaks.gemspec
|
51
|
+
- lib/yaks-html.rb
|
52
|
+
- lib/yaks/format/html.rb
|
53
|
+
- lib/yaks/format/template.html
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- yaks-html.gemspec
|
154
56
|
homepage: https://github.com/plexus/yaks
|
155
57
|
licenses:
|
156
58
|
- MIT
|
@@ -175,4 +77,5 @@ rubygems_version: 2.4.2
|
|
175
77
|
signing_key:
|
176
78
|
specification_version: 4
|
177
79
|
summary: HTML output format for Yaks
|
178
|
-
test_files:
|
80
|
+
test_files:
|
81
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
script: bundle exec rake $TASK
|
3
|
-
rvm:
|
4
|
-
- 1.9.3
|
5
|
-
- 2.0
|
6
|
-
- 2.1
|
7
|
-
- ruby-head
|
8
|
-
- rbx-2
|
9
|
-
- jruby
|
10
|
-
- jruby-head
|
11
|
-
env:
|
12
|
-
- TASK=yaks:rspec
|
13
|
-
- TASK=yaks:mutant
|
14
|
-
- TASK=yaks-html:rspec
|
15
|
-
- TASK=yaks-html:mutant
|
16
|
-
matrix:
|
17
|
-
allow_failures:
|
18
|
-
- rvm: ruby-head
|
19
|
-
- rvm: jruby-head
|
20
|
-
- env: TASK=yaks:mutant
|
21
|
-
- env: TASK=yaks-html:mutant
|
22
|
-
exclude:
|
23
|
-
- rvm: jruby
|
24
|
-
env: TASK=yaks:mutant
|
25
|
-
- rvm: jruby
|
26
|
-
env: TASK=yaks-html:mutant
|
27
|
-
|
28
|
-
- rvm: jruby-head
|
29
|
-
env: TASK=yaks:mutant
|
30
|
-
- rvm: jruby-head
|
31
|
-
env: TASK=yaks-html:mutant
|
32
|
-
|
33
|
-
- rvm: rbx-2
|
34
|
-
env: TASK=yaks:mutant
|
35
|
-
- rvm: rbx-2
|
36
|
-
env: TASK=yaks-html:mutant
|
data/ADDING_FORMATS.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Adding Extra Output Formats to Yaks
|
2
|
-
|
3
|
-
Individual output formats are each handled by a dedicated `Yaks::Serializer` class. These take a `Yaks::Resource` as input, and turn it into the requested output format.
|
4
|
-
|
5
|
-
A `Yaks::Resource` is created by "mapping" domain models by a `Yaks::Mapper`. In a `Yaks::Mapper` subclass a DSL is available to specify how to extract different types of information, for example attributes or links, and store them in a generalized way in a `Resource`.
|
6
|
-
|
7
|
-
Different formats have different features. Simple formats might just represent attributes, links, and subresources, other formats have queries, forms, or RDF identifiers. If a format represents data of a different nature, then the first step is to decide on a good and straightforward syntax to specify how to derive this data. This can then be stored in a `Yaks::Resource`, and formats that support it can use it, other formats can ignore it.
|
8
|
-
|
9
|
-
This is already the case, JSON-API ignores links for example.
|
10
|
-
|
11
|
-
So adding an output format is generally straightforward, as long as the information that the output format supports is already available in `Yaks::Resource`. In that case adding a `Yaks::Serializer::YourFormat` is all that is needed.
|
12
|
-
|
13
|
-
If the format has features that are not yet available then syntax needs to be added for those features. The guiding idea there is to try and find more than one format with the given feature, to make sure the intermediate abstraction is general and not tied to the specifics and vocabulary of a single format.
|
data/CHANGELOG.md
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
### Development
|
2
|
-
[full changelog](http://github.com/plexus/yaks/compare/v0.5.0...master)
|
3
|
-
|
4
|
-
### 0.5.0
|
5
|
-
|
6
|
-
* Yaks now serializes (returns a string), instead of returning a data structure. This is a preparatory step for supporting non-JSON formats. To get the old behavior back, do this
|
7
|
-
|
8
|
-
``` ruby
|
9
|
-
yaks = Yaks.new do
|
10
|
-
skip :serialize
|
11
|
-
end
|
12
|
-
```
|
13
|
-
|
14
|
-
* The old `after` hook has been removed, instead there are now generic hooks for all steps: `before`, `after`, `around`, `skip`; `:map`, `:format`, `:primitivize`, `:serialize`.
|
15
|
-
|
16
|
-
* By default Yaks uses `JSON.pretty_generate` as a JSON unparser. To use something else, for example `Oj.dump`, do this
|
17
|
-
|
18
|
-
``` ruby
|
19
|
-
yaks = Yaks.new do
|
20
|
-
json_serializer &Oj.method(:dump)
|
21
|
-
end
|
22
|
-
```
|
23
|
-
|
24
|
-
* Mapping a non-empty collection will try to infer the type, and hence rel of the nested items, based on the first object in the collection. This is only relevant for formats like HAL that don't have a top-level collection representation, and only matters when mapping a collection at the top level, not when mapping a collection from an association.
|
25
|
-
|
26
|
-
* Collection+JSON uses a link's "title" attribute to output a link's "name", to better correspond with other formats
|
27
|
-
|
28
|
-
* When registering a custom format (Yaks::Format subclass), the signature has changed
|
29
|
-
|
30
|
-
``` ruby
|
31
|
-
# 0.4.3
|
32
|
-
Format.register self, :collection_json, 'application/vnd.collection+json'
|
33
|
-
|
34
|
-
# 0.5.0
|
35
|
-
register :collection_json, :json, 'application/vnd.collection+json'
|
36
|
-
```
|
37
|
-
|
38
|
-
* `yaks.call` is now the preferred interface, rather than `yaks.serialize`, although there are no plans yet to remove the alias.
|
39
|
-
|
40
|
-
* The result of a call to `Yaks.new` now responds to `to_proc`, so you can treat it as a Proc/Symbol, e.g. `some_method &yaks`
|
41
|
-
|
42
|
-
* Improved YARD documentation
|
43
|
-
|
44
|
-
* 100% mutation coverage :trumpet: :tada:
|
45
|
-
|
46
|
-
### 0.4.3
|
47
|
-
|
48
|
-
* when specifying a rel_template, instead of allowing for {src} and {dest} fields, now a single {rel} field is expected, which corresponds more with typical usage.
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
Yaks.new do
|
52
|
-
rel_template 'http://my-api/docs/relationships/{rel}'
|
53
|
-
end
|
54
|
-
```
|
55
|
-
|
56
|
-
* Yaks::Serializer has been renamed to Yaks::Format
|
57
|
-
|
58
|
-
* Yaks::Mapper#{map_attributes,map_links,map_subresource} signature has changed, they now are responsible for adding themselves to a resource instance.
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
class FooMapper < Yaks::Mapper
|
62
|
-
def map_attributes(resource)
|
63
|
-
resource.update_attributes(:example => 'attribute')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
```
|
67
|
-
|
68
|
-
* Conditionally turn associations into links
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
class ShowMapper < Yaks::Mapper
|
72
|
-
has_many :events, href: '/show/{id}/events', link_if: ->{ events.count > 50 }
|
73
|
-
end
|
74
|
-
```
|
75
|
-
|
76
|
-
* Reify `Yaks::Mapper::Attribute`
|
77
|
-
|
78
|
-
* Remove `Yaks::Mapper#filter`, instead override `#attributes` or `#associations` to filter things out, for example:
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
class SongMapper
|
82
|
-
attributes :title, :duration, :lyrics
|
83
|
-
has_one :artist
|
84
|
-
has_one :album
|
85
|
-
|
86
|
-
def minimal?
|
87
|
-
env['HTTP_PREFER'] =~ /minimal/
|
88
|
-
end
|
89
|
-
|
90
|
-
def attributes
|
91
|
-
if minimal?
|
92
|
-
super.reject {|attr| attr.name.equal? :lyrics } # These are instances of Yaks::Mapper::Attribute
|
93
|
-
else
|
94
|
-
super
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def associations
|
99
|
-
return [] if minimal?
|
100
|
-
super
|
101
|
-
end
|
102
|
-
end
|
103
|
-
```
|
104
|
-
|
105
|
-
* Give Attribute, Link, Association a common interface : `add_to_resource(resource, mapper, context)`
|
106
|
-
* Add persistent update methods to `Yaks::Resource`
|
107
|
-
|
108
|
-
### v0.4.2
|
109
|
-
|
110
|
-
* JSON-API: render self links as href attributes
|
111
|
-
* HAL: render has_one returning nil as null, not as {}
|
112
|
-
* Keep track of the mapper stack, useful for figuring out if mapping the top level response or not, or for accessing parent
|
113
|
-
* Change Serializer.new(resource, options).serialize to Serializer.new(options).call(resource) for cosistency of "pipeline" interface
|
114
|
-
* Make Yaks::CollectionMapper#collection overridable for pagination
|
115
|
-
* Don't render links from custom link methods (link :foo, :method_that_generates_url) that return nil
|
116
|
-
|
117
|
-
### v0.4.1
|
118
|
-
|
119
|
-
* Change how env is passed to yaks.serialize to match docs
|
120
|
-
* Fix JSON-API bug (#18 reported by Nicolas Blanco)
|
121
|
-
* Don't pluralize has_one association names in JSON-API
|
122
|
-
|
123
|
-
## v0.4.0
|
124
|
-
|
125
|
-
* Introduce after {} post-processing hook
|
126
|
-
* Streamline interfaces and variable names, especially the use of `call`
|
127
|
-
* Improve deriving mappers automatically, even with Rails style autoloading
|
128
|
-
* Give CollectionResource a members_rel, for HAL-like formats with no top-level collection concept
|
129
|
-
* Switch back to using `src` and `dest` as the rel-template keys, instead of `association_name`
|
130
|
-
* deprecate `mapper_namespace` in favor of `namespace`
|
131
|
-
|
132
|
-
### v0.4.0.rc1
|
133
|
-
|
134
|
-
* Introduce Yaks.new as the main public interface
|
135
|
-
* Fix JsonApiSerializer and make it compliant with current spec
|
136
|
-
* Remove Hamster dependency, Yaks new uses plain old Ruby arrays and hashes
|
137
|
-
* Remove `RelRegistry` and `ProfileRegistry` in favor of a simpler explicit syntax + policy based fallback
|
138
|
-
* Add more policy derivation hooks, plus make `DefaultPolicy` template for rel urls configurable
|
139
|
-
* Optionally take a Rack env hash, pass it around so mappers can inspect it
|
140
|
-
* Honor the HTTP Accept header if it is present in the rack env
|
141
|
-
* Add map_to_primitive configuration option
|
142
|
-
|
143
|
-
## v0.3.0
|
144
|
-
|
145
|
-
* Allow partial expansion of templates, expand certain fields, leave others as URI template in the result.
|
146
|
-
|
147
|
-
## v0.2.0
|
148
|
-
|
149
|
-
* links can now take a simple for a template to compute a link just like an attribute
|
data/Gemfile
DELETED
data/IDENTIFIERS.md
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
# Identifiers
|
2
|
-
|
3
|
-
In Yaks, and Hypermedia message formats in general, a number of different types of identifiers are used. Some are full URIs and correspond with well defined specs. Some are just short identifers that are easy to program with.
|
4
|
-
|
5
|
-
Understanding these types of identifiers is key to creating a unifying model of a "Resource" that can be shared across output formats. We want to unify as much as possible across formats, without conflating things that are really not the same.
|
6
|
-
|
7
|
-
This document reflects my current limited understanding of things, based on possibly incorrect assumptions. Feedback is more than welcome.
|
8
|
-
|
9
|
-
## rels
|
10
|
-
|
11
|
-
As used in HTML and Atom, these identifiers say what the relationship is between a resource and another resource it links to. There is a [registry of names](http://www.iana.org/assignments/link-relations/link-relations.xhtml), e.g. self, next, profile, stylesheet. Custom rels need to be fully qualified URLs. Keep in mind that these are simply opaque identifiers, but by using a known protocol like http they can be used to point at documentation.
|
12
|
-
|
13
|
-
Some examples
|
14
|
-
|
15
|
-
```
|
16
|
-
copyright
|
17
|
-
stylesheet
|
18
|
-
http://api.example.com/rel/author
|
19
|
-
http://api.example.com/api-docs/relationships#comment
|
20
|
-
custom_scheme:foo
|
21
|
-
/order
|
22
|
-
```
|
23
|
-
|
24
|
-
The last example is a relative URL, which would have to be expanded against the source URL of the document it is mentioned in.
|
25
|
-
|
26
|
-
In Yaks both links and subresources are specified with their rel(ationship).
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
class PersonMapper < Yaks::Mapper
|
30
|
-
link :self, '/people/{id}'
|
31
|
-
link 'http://api.example.com/rels#friends', '/people/{id}/friends'
|
32
|
-
|
33
|
-
has_one :address, rel: 'http://api.example.com/rels#address'
|
34
|
-
end
|
35
|
-
```
|
36
|
-
|
37
|
-
For subresources the rel can be omitted, in which case it will be inferred based on the rel_template:
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
$yaks = Yaks.new do
|
41
|
-
rel_template 'http://api.example.com/rels/{dest}'
|
42
|
-
end
|
43
|
-
```
|
44
|
-
|
45
|
-
Links and subresources are rendered keyed by rel in HAL and Collection+JSON. JSON-API renders `self` links as the `href` of a resource.
|
46
|
-
|
47
|
-
## profiles
|
48
|
-
|
49
|
-
A specific IANA registered rel type is profile.
|
50
|
-
|
51
|
-
> Profile: Identifying that a resource representation conforms to a certain profile, without affecting the non-profile semantics of the resource representation.
|
52
|
-
|
53
|
-
Profile basically adds a layer of semantics on top of the hypermedia message format (e.g. HAL, Collection+JSON), which in turns defines semantics on top of a serialization format (JSON, XML, EDN). Loosely speaking it could be seen as the "type" or "class". For example if you know the profile of a resource, you might know you can expect to find a "name", "date_of_birth", or "post_body" field.
|
54
|
-
|
55
|
-
## "type"
|
56
|
-
|
57
|
-
Despite the appealing rigor of having fully qualified URIs to identify things, sometimes you just want to call a person a `person`. In Yaks we call these short identifier the *type* for lack of a better word. In some cases, notably JSON-API, they are used literally in the output. More often they are used to derive full URIs based on a template.
|
58
|
-
|
59
|
-
The type of a mapper is inferred from its class name, but can be set explicitly as well.
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
class CatMapper < Yaks::Mapper
|
63
|
-
end
|
64
|
-
|
65
|
-
# type = "cat"
|
66
|
-
```
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
class CatMapper < Yaks::Mapper
|
70
|
-
type 'feline'
|
71
|
-
end
|
72
|
-
|
73
|
-
# type => "feline"
|
74
|
-
```
|
75
|
-
|
76
|
-
## rdf class
|
77
|
-
|
78
|
-
RDF (Resource Description Framework) is a set of specifications for use in "semantic web" applications. RDF is based on "ontologies" that precisely define a "vocabulary" of "classes" and "predicates". An example class identifier for all Merlot wines could be
|
79
|
-
|
80
|
-
> http://www.w3.org/TR/2004/REC-owl-guide-20040210/wine#Merlot
|
81
|
-
|
82
|
-
(source [wikipedia](http://en.wikipedia.org/wiki/Resource_Description_Framework))
|
83
|
-
|
84
|
-
Not currently used by Yaks, but might become important when implementing support for JSON-LD or other RDF serialization formats.
|
85
|
-
|
86
|
-
## CURIES
|
87
|
-
|
88
|
-
CURIES are "compact uris". The HAL format uses this so it can have the rigor of fully specified rels, with the ease of use of short-name "type" identifiers. The mechanism is similar to how one specifies and uses XML namespaces.
|
89
|
-
|
90
|
-
From the HAL spec:
|
91
|
-
|
92
|
-
```json
|
93
|
-
{
|
94
|
-
"_links": {
|
95
|
-
"self": { "href": "/orders" },
|
96
|
-
"curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}", "templated": true }],
|
97
|
-
"next": { "href": "/orders?page=2" },
|
98
|
-
"ea:find": {
|
99
|
-
"href": "/orders{?id}",
|
100
|
-
"templated": true
|
101
|
-
},
|
102
|
-
"ea:admin": [{
|
103
|
-
"href": "/admins/2",
|
104
|
-
"title": "Fred"
|
105
|
-
}, {
|
106
|
-
"href": "/admins/5",
|
107
|
-
"title": "Kate"
|
108
|
-
}]
|
109
|
-
}
|
110
|
-
}
|
111
|
-
```
|
112
|
-
|
113
|
-
In this case "ea:find" is just a shorthand for "http://example.com/docs/rels/find".
|