yaks 0.11.0 → 0.12.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 +4 -4
- data/find_missing_tests.rb +1 -1
- data/lib/yaks/format/halo.rb +1 -1
- data/lib/yaks/mapper/association_mapper.rb +1 -1
- data/lib/yaks/mapper/attribute.rb +7 -4
- data/lib/yaks/null_resource.rb +1 -1
- data/lib/yaks/reader/json_api.rb +4 -4
- data/lib/yaks/resource/form.rb +1 -1
- data/lib/yaks/util.rb +1 -1
- data/lib/yaks/version.rb +1 -1
- data/spec/acceptance/acceptance_spec.rb +1 -1
- data/spec/acceptance/json_shared_examples.rb +1 -1
- data/spec/unit/yaks/config_spec.rb +3 -3
- data/spec/unit/yaks/configurable_spec.rb +2 -0
- data/spec/unit/yaks/format/collection_json_spec.rb +1 -1
- data/spec/unit/yaks/mapper/association_spec.rb +3 -3
- data/spec/unit/yaks/mapper/attribute_spec.rb +84 -3
- data/spec/unit/yaks/mapper/form/fieldset_spec.rb +1 -1
- data/spec/unit/yaks/mapper/has_many_spec.rb +1 -1
- data/spec/unit/yaks/mapper/has_one_spec.rb +1 -1
- data/spec/unit/yaks/pipeline_spec.rb +1 -1
- data/spec/unit/yaks/resource/link_spec.rb +1 -1
- data/spec/unit/yaks/runner_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 558f64d7a2d93038fc00cad3ff0c7442b3458e6f
|
4
|
+
data.tar.gz: 60e1a98b810c825d8bc44efa69fda28656970153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 362873163152bd0ca6466a70b0aeb2c58bb8b024ead9920af7869697aef5d6a52a5b50a5b31973afee16213da5f1dc85734e833ca9a8b9b9b634d10b047bfa1f
|
7
|
+
data.tar.gz: 9ab584641aacf534cdd60c42f13229073867f8e3f83973d78ef92cd268574656272c15311a7091cc3764dab74f89612e0d51a09d2a02009867a210406958de1d
|
data/find_missing_tests.rb
CHANGED
@@ -20,7 +20,7 @@ env = Mutant::Env::Bootstrap.call(Mutant::CLI.call(args))
|
|
20
20
|
integration = env.config.integration
|
21
21
|
|
22
22
|
integration.setup
|
23
|
-
binding.pry if integration.all_tests.empty?
|
23
|
+
binding.pry if integration.all_tests.empty? # rubocop:disable Lint/Debugger
|
24
24
|
|
25
25
|
env.subjects.each do |subject|
|
26
26
|
match_expression = subject.match_expressions.first
|
data/lib/yaks/format/halo.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
module Yaks
|
2
2
|
class Mapper
|
3
3
|
class Attribute
|
4
|
-
|
5
|
-
include Util
|
4
|
+
extend Forwardable, Util
|
5
|
+
include Attribs.new(:name, :block, if: true), Util
|
6
6
|
|
7
|
-
def self.create(name,
|
8
|
-
new(name: name, block: block)
|
7
|
+
def self.create(name, options = {}, &block)
|
8
|
+
new(options.merge(name: name, block: block))
|
9
9
|
end
|
10
10
|
|
11
11
|
def add_to_resource(resource, mapper, _context)
|
12
|
+
return resource unless Resolve(self.if, mapper)
|
13
|
+
|
12
14
|
if block
|
13
15
|
attribute = Resolve(block, mapper)
|
14
16
|
else
|
15
17
|
attribute = mapper.load_attribute(name)
|
16
18
|
end
|
19
|
+
|
17
20
|
resource.merge_attributes(name => attribute)
|
18
21
|
end
|
19
22
|
end
|
data/lib/yaks/null_resource.rb
CHANGED
data/lib/yaks/reader/json_api.rb
CHANGED
@@ -7,13 +7,13 @@ module Yaks
|
|
7
7
|
if parsed_json['data'].is_a?(Array)
|
8
8
|
CollectionResource.new(
|
9
9
|
attributes: parsed_json['meta'].nil? ? nil : {meta: parsed_json['meta']},
|
10
|
-
members: parsed_json['data'].map { |data| call('data'
|
10
|
+
members: parsed_json['data'].map { |data| call('data' => data, 'included' => included) }
|
11
11
|
)
|
12
12
|
else
|
13
13
|
attributes = parsed_json['data'].dup
|
14
14
|
links = attributes.delete('links') || {}
|
15
15
|
relationships = attributes.delete('relationships') || {}
|
16
|
-
type
|
16
|
+
type = attributes.delete('type')
|
17
17
|
attributes.merge!(attributes.delete('attributes') || {})
|
18
18
|
|
19
19
|
embedded = convert_embedded(Hash[relationships], included)
|
@@ -48,14 +48,14 @@ module Yaks
|
|
48
48
|
CollectionResource.new(
|
49
49
|
members: data.map { |link|
|
50
50
|
data = included.find{ |item| (item['id'] == link['id']) && (item['type'] == link['type']) }
|
51
|
-
call('data'
|
51
|
+
call('data' => data, 'included' => included)
|
52
52
|
},
|
53
53
|
rels: [rel]
|
54
54
|
)
|
55
55
|
end
|
56
56
|
else
|
57
57
|
data = included.find{ |item| (item['id'] == data['id']) && (item['type'] == data['type']) }
|
58
|
-
call('data'
|
58
|
+
call('data' => data, 'included' => included).with(rels: [rel])
|
59
59
|
end
|
60
60
|
end.compact
|
61
61
|
end
|
data/lib/yaks/resource/form.rb
CHANGED
data/lib/yaks/util.rb
CHANGED
@@ -46,7 +46,7 @@ module Yaks
|
|
46
46
|
# A proc or a plain value
|
47
47
|
# @param [Object] context
|
48
48
|
# (optional) A context used to instance_eval the proc
|
49
|
-
def Resolve(maybe_proc, context = nil)
|
49
|
+
def Resolve(maybe_proc, context = nil) # rubocop:disable Style/MethodName
|
50
50
|
if maybe_proc.respond_to?(:to_proc) && !maybe_proc.instance_of?(Symbol)
|
51
51
|
if context
|
52
52
|
if maybe_proc.arity > 0
|
data/lib/yaks/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.shared_examples_for 'JSON Writer' do |fixture_name|
|
2
2
|
describe 'Yaks::Resource => JSON' do
|
3
|
-
let(:object)
|
3
|
+
let(:object) { load_yaml_fixture(fixture_name) }
|
4
4
|
let(:json_fixture) { load_json_fixture("#{fixture_name}.#{format_name}") }
|
5
5
|
let(:serialized) {
|
6
6
|
yaks_config.call(object, hooks: [[:skip, :serialize]], format: format_name)
|
@@ -12,9 +12,9 @@ RSpec.describe Yaks::Config do
|
|
12
12
|
its(:default_format) { should equal :hal }
|
13
13
|
its(:policy_class) { should <= Yaks::DefaultPolicy }
|
14
14
|
its(:primitivize) { should be_a Yaks::Primitivize }
|
15
|
-
its(:serializers) { should eql(Yaks::Serializer.all)
|
16
|
-
its(:hooks) { should eql([])
|
17
|
-
its(:format_options_hash) { should eql({})}
|
15
|
+
its(:serializers) { should eql(Yaks::Serializer.all) }
|
16
|
+
its(:hooks) { should eql([]) }
|
17
|
+
its(:format_options_hash) { should eql({}) }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -322,7 +322,7 @@ RSpec.describe Yaks::Format::CollectionJson do
|
|
322
322
|
],
|
323
323
|
"queries" => [
|
324
324
|
{"href" => "/foo", "rel" => "search", "prompt" => "My query prompt",
|
325
|
-
"data" =>
|
325
|
+
"data" => [
|
326
326
|
{"name" => "foo", "value" => ""},
|
327
327
|
{"name" => "bar", "value" => "", "prompt" => "My Bar Field"}
|
328
328
|
]
|
@@ -56,7 +56,7 @@ RSpec.describe Yaks::Mapper::Association do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
context 'with a truthy condition' do
|
59
|
-
let(:if)
|
59
|
+
let(:if) { ->{ true } }
|
60
60
|
|
61
61
|
it 'should add the association' do
|
62
62
|
expect(association.add_to_resource(Yaks::Resource.new, parent_mapper, yaks_context).subresources.length).to be 1
|
@@ -70,7 +70,7 @@ RSpec.describe Yaks::Mapper::Association do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
context 'with a falsey condition' do
|
73
|
-
let(:if)
|
73
|
+
let(:if) { ->{ false } }
|
74
74
|
|
75
75
|
it 'should not add the association' do
|
76
76
|
expect(association.add_to_resource(Yaks::Resource.new, parent_mapper, yaks_context).subresources.length).to be 0
|
@@ -182,7 +182,7 @@ RSpec.describe Yaks::Mapper::Association do
|
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'should not munge the options hash' do
|
185
|
-
opts
|
185
|
+
opts = {mapper: :foo}
|
186
186
|
association_class.create(:foo, opts)
|
187
187
|
expect(opts).to eql(mapper: :foo)
|
188
188
|
end
|
@@ -2,7 +2,6 @@ RSpec.describe Yaks::Mapper::Attribute do
|
|
2
2
|
include_context 'yaks context'
|
3
3
|
|
4
4
|
let(:attribute_with_block) { described_class.create(:the_name) { "Alice" } }
|
5
|
-
|
6
5
|
subject(:attribute) { described_class.create(:the_name) }
|
7
6
|
fake(:mapper)
|
8
7
|
|
@@ -13,10 +12,11 @@ RSpec.describe Yaks::Mapper::Attribute do
|
|
13
12
|
|
14
13
|
describe ".create" do
|
15
14
|
its(:name) { should be :the_name }
|
15
|
+
its(:if) { should be_truthy }
|
16
16
|
its(:block) { should be_nil }
|
17
17
|
|
18
|
-
it "should accept
|
19
|
-
expect{described_class.create(:the_name
|
18
|
+
it "should accept only the name" do
|
19
|
+
expect{described_class.create(:the_name)}.not_to raise_error()
|
20
20
|
end
|
21
21
|
|
22
22
|
context "with block" do
|
@@ -28,14 +28,95 @@ RSpec.describe Yaks::Mapper::Attribute do
|
|
28
28
|
expect(subject.block.call).to eq("Alice")
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
describe "options" do
|
33
|
+
|
34
|
+
let(:object) { Struct.new(:x, :y, :returns_nil).new(3, 4, nil) }
|
35
|
+
|
36
|
+
let(:mapper_class) do
|
37
|
+
Class.new(Yaks::Mapper) do
|
38
|
+
type 'foo'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:mapper) do
|
43
|
+
mapper_class.new(yaks_context).tap do |mapper|
|
44
|
+
mapper.call(object) # set @object
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
subject(:attribute) { described_class.create(:the_name, options) }
|
49
|
+
|
50
|
+
context 'with :if defined and resolving to false' do
|
51
|
+
|
52
|
+
let(:options) { {if: ->{ false }} }
|
53
|
+
|
54
|
+
it 'should not render the attribute' do
|
55
|
+
expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context)).not_to eql(
|
56
|
+
Yaks::Resource.new(attributes: {the_name: 123})
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with :if defined and resolving to true' do
|
62
|
+
let(:options) { {if: ->{ true }} }
|
63
|
+
|
64
|
+
it 'should render the attribute' do
|
65
|
+
expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context)).to eql(
|
66
|
+
Yaks::Resource.new(attributes: {the_name: 123})
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with :if defined and resolving to true via instance_eval' do
|
72
|
+
let(:options) { {if: ->{ object.name.length > 2 } } }
|
73
|
+
|
74
|
+
it 'should render the attribute' do
|
75
|
+
expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context)).to eql(
|
76
|
+
Yaks::Resource.new(attributes: {the_name: 123})
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
31
82
|
end
|
32
83
|
|
33
84
|
describe "#add_to_resource" do
|
85
|
+
|
86
|
+
let(:options) { {if: ->{ true }} }
|
87
|
+
let(:options_false) { {if: ->{ 0 == 1 }} }
|
88
|
+
let(:attribute_with_block_and_false_options) {described_class.create(:the_name,options_false) { "Alice" } }
|
89
|
+
let(:attribute_with_block_and_options) { described_class.create(:the_name,options) { "Alice" } }
|
90
|
+
|
91
|
+
|
92
|
+
|
34
93
|
it "should add itself to a resource based on a lookup" do
|
35
94
|
expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context))
|
36
95
|
.to eql(Yaks::Resource.new(attributes: {the_name: 123}))
|
37
96
|
end
|
38
97
|
|
98
|
+
context "when the attribute has a block and true options" do
|
99
|
+
subject(:attribute) { attribute_with_block_and_options }
|
100
|
+
|
101
|
+
it "should add itself to a resource with the block value" do
|
102
|
+
expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context))
|
103
|
+
.to eql(Yaks::Resource.new(attributes: {the_name: "Alice"}))
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when the attribute has a block and false options" do
|
110
|
+
subject(:attribute) { attribute_with_block_and_false_options }
|
111
|
+
|
112
|
+
it "should not add itself to a resource with the block value" do
|
113
|
+
expect(attribute.add_to_resource(Yaks::Resource.new, mapper, yaks_context))
|
114
|
+
.not_to eql(Yaks::Resource.new(attributes: {the_name: "Alice"}))
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
119
|
+
|
39
120
|
context "when the attribute has a block" do
|
40
121
|
subject(:attribute) { attribute_with_block }
|
41
122
|
|
@@ -72,7 +72,7 @@ RSpec.describe Yaks::Mapper::HasMany do
|
|
72
72
|
describe '#collection_mapper' do
|
73
73
|
let(:collection_mapper) { Yaks::Undefined }
|
74
74
|
|
75
|
-
subject(:has_many)
|
75
|
+
subject(:has_many) { described_class.new(name: :name, item_mapper: :mapper, rel: :rel, collection_mapper: collection_mapper) }
|
76
76
|
|
77
77
|
context 'when the collection mapper is undefined' do
|
78
78
|
it 'should derive one from collection and policy' do
|
@@ -10,7 +10,7 @@ RSpec.describe Yaks::Resource::Link do
|
|
10
10
|
its(:options) { should eql(title: 'mr. spectacular') }
|
11
11
|
|
12
12
|
describe '#title' do
|
13
|
-
its(:title)
|
13
|
+
its(:title) { should eql('mr. spectacular') }
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#templated?' do
|
@@ -20,7 +20,7 @@ RSpec.describe Yaks::Runner do
|
|
20
20
|
let(:runner) {
|
21
21
|
Class.new(described_class) do
|
22
22
|
def steps
|
23
|
-
[ [:step1, proc { |x| x + 35
|
23
|
+
[ [:step1, proc { |x| x + 35 }],
|
24
24
|
[:step2, proc { |x, env| "#{env[:foo]}[#{x} #{x}]" }] ]
|
25
25
|
end
|
26
26
|
end.new(object: object, config: config, options: options)
|
@@ -337,7 +337,7 @@ RSpec.describe Yaks::Runner do
|
|
337
337
|
}
|
338
338
|
}
|
339
339
|
|
340
|
-
let(:object)
|
340
|
+
let(:object) { "foo" }
|
341
341
|
|
342
342
|
it 'should only run the mapper' do
|
343
343
|
expect(runner.map).to eql "mapped[foo]"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Brasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|
@@ -465,7 +465,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
465
465
|
version: '0'
|
466
466
|
requirements: []
|
467
467
|
rubyforge_project:
|
468
|
-
rubygems_version: 2.
|
468
|
+
rubygems_version: 2.5.1
|
469
469
|
signing_key:
|
470
470
|
specification_version: 4
|
471
471
|
summary: Serialize to hypermedia. HAL, JSON-API, etc.
|