yaks 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -0
  3. data/Rakefile +58 -38
  4. data/lib/yaks.rb +3 -4
  5. data/lib/yaks/attributes.rb +23 -10
  6. data/lib/yaks/config.rb +4 -0
  7. data/lib/yaks/configurable.rb +16 -21
  8. data/lib/yaks/format.rb +1 -1
  9. data/lib/yaks/format/collection_json.rb +9 -0
  10. data/lib/yaks/format/halo.rb +16 -13
  11. data/lib/yaks/html5_forms.rb +22 -1
  12. data/lib/yaks/mapper.rb +5 -5
  13. data/lib/yaks/mapper/attribute.rb +1 -1
  14. data/lib/yaks/mapper/class_methods.rb +3 -1
  15. data/lib/yaks/mapper/config.rb +9 -16
  16. data/lib/yaks/mapper/form.rb +41 -0
  17. data/lib/yaks/mapper/form/field.rb +62 -0
  18. data/lib/yaks/null_resource.rb +1 -1
  19. data/lib/yaks/resource.rb +7 -3
  20. data/lib/yaks/resource/form.rb +31 -0
  21. data/lib/yaks/runner.rb +11 -11
  22. data/lib/yaks/stateful_builder.rb +11 -7
  23. data/lib/yaks/util.rb +3 -2
  24. data/lib/yaks/version.rb +1 -1
  25. data/spec/acceptance/models.rb +1 -1
  26. data/spec/json/confucius.halo.json +2 -4
  27. data/spec/json/plant_collection.collection.json +4 -0
  28. data/spec/unit/yaks/attributes_spec.rb +79 -0
  29. data/spec/unit/yaks/configurable_spec.rb +32 -2
  30. data/spec/unit/yaks/format/collection_json_spec.rb +59 -27
  31. data/spec/unit/yaks/format/halo_spec.rb +3 -0
  32. data/spec/unit/yaks/mapper/{control → form}/field_spec.rb +3 -3
  33. data/spec/unit/yaks/mapper/{control_spec.rb → form_spec.rb} +12 -12
  34. data/spec/unit/yaks/mapper_spec.rb +10 -10
  35. data/spec/unit/yaks/null_resource_spec.rb +50 -7
  36. data/spec/unit/yaks/resource_spec.rb +4 -4
  37. data/spec/unit/yaks/runner_spec.rb +38 -2
  38. data/spec/unit/yaks/util_spec.rb +42 -0
  39. metadata +20 -58
  40. data/lib/yaks/mapper/control.rb +0 -82
  41. data/lib/yaks/resource/control.rb +0 -11
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.7.6
4
+ version: 0.7.7
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-11-18 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflection
@@ -269,14 +269,15 @@ files:
269
269
  - lib/yaks/mapper/attribute.rb
270
270
  - lib/yaks/mapper/class_methods.rb
271
271
  - lib/yaks/mapper/config.rb
272
- - lib/yaks/mapper/control.rb
272
+ - lib/yaks/mapper/form.rb
273
+ - lib/yaks/mapper/form/field.rb
273
274
  - lib/yaks/mapper/has_many.rb
274
275
  - lib/yaks/mapper/has_one.rb
275
276
  - lib/yaks/mapper/link.rb
276
277
  - lib/yaks/null_resource.rb
277
278
  - lib/yaks/primitivize.rb
278
279
  - lib/yaks/resource.rb
279
- - lib/yaks/resource/control.rb
280
+ - lib/yaks/resource/form.rb
280
281
  - lib/yaks/resource/link.rb
281
282
  - lib/yaks/runner.rb
282
283
  - lib/yaks/serializer.rb
@@ -317,6 +318,7 @@ files:
317
318
  - spec/unit/yaks/default_policy_spec.rb
318
319
  - spec/unit/yaks/format/collection_json_spec.rb
319
320
  - spec/unit/yaks/format/hal_spec.rb
321
+ - spec/unit/yaks/format/halo_spec.rb
320
322
  - spec/unit/yaks/format/html_spec.rb
321
323
  - spec/unit/yaks/format/json_api_spec.rb
322
324
  - spec/unit/yaks/format_spec.rb
@@ -327,8 +329,8 @@ files:
327
329
  - spec/unit/yaks/mapper/attribute_spec.rb
328
330
  - spec/unit/yaks/mapper/class_methods_spec.rb
329
331
  - spec/unit/yaks/mapper/config_spec.rb
330
- - spec/unit/yaks/mapper/control/field_spec.rb
331
- - spec/unit/yaks/mapper/control_spec.rb
332
+ - spec/unit/yaks/mapper/form/field_spec.rb
333
+ - spec/unit/yaks/mapper/form_spec.rb
332
334
  - spec/unit/yaks/mapper/has_many_spec.rb
333
335
  - spec/unit/yaks/mapper/has_one_spec.rb
334
336
  - spec/unit/yaks/mapper/link_spec.rb
@@ -349,60 +351,19 @@ licenses:
349
351
  - MIT
350
352
  metadata:
351
353
  changelog: |-
352
- Much expanded form support, simplified link DSL, pretty-print objects
353
- to Ruby code.
354
+ General extension and improvements to form handling.
354
355
 
355
- Breaking change: using a symbol instead of link template no longer
356
- works, use a lambda.
356
+ Add top level links in Collection+JSON (Carles Jove i Buxeda)
357
357
 
358
- link :foo, :bar
358
+ The mapper DSL method "control" has been renamed to "form". There is a
359
+ deprecated alias available.
359
360
 
360
- Becomes
361
+ Add Yaks::Resource#find_form for querying a resource for an embedded
362
+ form by name.
361
363
 
362
- link :foo, ->{ bar }
363
-
364
- Strictly speaking the equivalent version would be `link :foo, ->{
365
- load_attribute(:bar) }`. Depending on if `bar` is implemented on the
366
- mapper or is an attribute of the object, this would simplify to `link
367
- :foo, ->{ bar }` or `link :foo, ->{ object.bar }` respectively.
368
-
369
- The form control DSL has been expanded, instead of `field type:
370
- 'text'` and similar there are now aliases, e.g. `text :name, value:
371
- 'foo'`.
372
-
373
- All attributes on the form control itself, and on fields, now
374
- optionally take a lambda (any `#to_proc`-able) for dynamic
375
- content. e.g.
376
-
377
- control :add_product do
378
- method 'POST'
379
- action ->{ '/cart/#{cart.id}/line_items' }
380
- hidden :product_id, value: -> { product.id }
381
- number :quantity, value: 0
382
- end
383
-
384
- As with lambdas used for links, i
385
- post_install_message: |2
386
-
387
- Breaking Changes in Yaks 0.7.6
388
- ==============================
389
- Breaking change: using a symbol instead of link template no longer
390
- works, use a lambda.
391
-
392
- link :foo, :bar
393
-
394
- Becomes
395
-
396
- link :foo, ->{ bar }
397
-
398
- Strictly speaking the equivalent version would be `link :foo, ->{
399
- load_attribute(:bar) }`. Depending on if `bar` is implemented on the
400
- mapper or is an attribute of the object, this would simplify to `link
401
- :foo, ->{ bar }` or `link :foo, ->{ object.bar }` respectively.
402
-
403
- The `href` attribute of a control has been renamed `action`, in line
404
- with the attribute name in HTML. An alias is available but will output
405
- a deprecation warning.
364
+ Introduce yaks.map() so you can only call the mapping step without
365
+ running the whole pipeline.
366
+ post_install_message:
406
367
  rdoc_options: []
407
368
  require_paths:
408
369
  - lib
@@ -457,6 +418,7 @@ test_files:
457
418
  - spec/unit/yaks/default_policy_spec.rb
458
419
  - spec/unit/yaks/format/collection_json_spec.rb
459
420
  - spec/unit/yaks/format/hal_spec.rb
421
+ - spec/unit/yaks/format/halo_spec.rb
460
422
  - spec/unit/yaks/format/html_spec.rb
461
423
  - spec/unit/yaks/format/json_api_spec.rb
462
424
  - spec/unit/yaks/format_spec.rb
@@ -467,8 +429,8 @@ test_files:
467
429
  - spec/unit/yaks/mapper/attribute_spec.rb
468
430
  - spec/unit/yaks/mapper/class_methods_spec.rb
469
431
  - spec/unit/yaks/mapper/config_spec.rb
470
- - spec/unit/yaks/mapper/control/field_spec.rb
471
- - spec/unit/yaks/mapper/control_spec.rb
432
+ - spec/unit/yaks/mapper/form/field_spec.rb
433
+ - spec/unit/yaks/mapper/form_spec.rb
472
434
  - spec/unit/yaks/mapper/has_many_spec.rb
473
435
  - spec/unit/yaks/mapper/has_one_spec.rb
474
436
  - spec/unit/yaks/mapper/link_spec.rb
@@ -1,82 +0,0 @@
1
- module Yaks
2
- class Mapper
3
- class Control
4
- extend Util::Deprecated
5
- include Attributes.new(
6
- name: nil, action: nil, title: nil, method: nil, media_type: nil, fields: []
7
- ),
8
- Configurable
9
-
10
- alias enctype media_type
11
- deprecated_alias :href, :action
12
-
13
- def self.create(name = nil, options = {})
14
- new({name: name}.merge(options))
15
- end
16
-
17
- def add_to_resource(resource, mapper, _context)
18
- resource.add_control(to_resource(mapper))
19
- end
20
-
21
- def to_resource(mapper)
22
- attrs = {
23
- fields: resource_fields(mapper),
24
- action: mapper.expand_uri(action, true)
25
- }
26
- [:name, :title, :method, :media_type].each do |attr|
27
- attrs[attr] = mapper.expand_value(public_send(attr))
28
- end
29
- Resource::Control.new(attrs)
30
- end
31
-
32
- def resource_fields(mapper)
33
- fields.map { |field| field.to_resource(mapper) }
34
- end
35
-
36
- class Field
37
- include Attributes.new(:name, label: nil, type: "text", value: nil, options: []),
38
- Configurable
39
-
40
- def self.create(*args, &block)
41
- attrs = args.last.instance_of?(Hash) ? args.pop : {}
42
- if name = args.shift
43
- attrs = attrs.merge(name: name)
44
- end
45
- new(attrs)
46
- end
47
-
48
- def to_resource(mapper)
49
- Resource::Control::Field.new(
50
- [:name, :label, :type, :value].each_with_object({}) do |attr, attrs|
51
- attrs[attr] = mapper.expand_value(public_send(attr))
52
- end.merge(options: options.map(&:to_resource))
53
- )
54
- end
55
-
56
- class Option
57
- include Attributes.new(:value, :label, selected: false)
58
-
59
- def self.create(value, opts = {})
60
- new(opts.merge(value: value))
61
- end
62
-
63
- def to_resource
64
- to_h #placeholder
65
- end
66
- end
67
-
68
- config_method :option,
69
- append_to: :options,
70
- create: Option
71
- end
72
-
73
- FieldBuilder = StatefulBuilder.new(Field, [:name, :label, :type, :value, :option])
74
-
75
- config_method :field, create: FieldBuilder, append_to: :fields
76
-
77
- HTML5Forms::INPUT_TYPES.each do |type|
78
- config_method type, create: FieldBuilder, append_to: :fields, defaults: { type: type }
79
- end
80
- end
81
- end
82
- end
@@ -1,11 +0,0 @@
1
- module Yaks
2
- class Resource
3
- class Control
4
- include Yaks::Mapper::Control.attributes
5
-
6
- class Field
7
- include Yaks::Mapper::Control::Field.attributes
8
- end
9
- end
10
- end
11
- end