dato 0.3.22 → 0.3.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 971cda53136a4caf43ad4ed96b5d257d7f3fc2d8
4
- data.tar.gz: cce1d9764ab6e822e70e0c9332d351c6e3ef5fc9
3
+ metadata.gz: 4f1dee8287f371f80c0d9f92c8c979a2857606e7
4
+ data.tar.gz: 94a2edd19020f70b7a5cb843fd7f75fe4511b00f
5
5
  SHA512:
6
- metadata.gz: c775322fa8d551bdeae8aa4b095cb0ec6758fbb14708ab62e460f41282e1d996d4e2d99e63269333a1d1856dbf9a5d8f26caa0ab6469c23aea91b9440ea5bd03
7
- data.tar.gz: 3c6b2c4ca3886969915f06fd27e7aa926f050b0ec343ac67aa4346059a1c1e9e6c8aeefd7ad510abfd8af2f76a95f0e5bffa40cb29f5f73b3dd479bc6b1be8da
6
+ metadata.gz: 034eb1820be90435bac07c73b816c8bfbee0ebca17ca5f152867c5bd761c6a09b39a0405a002b783bef1c587d8ea13f788052330349c7023f10d8a8093958ec6
7
+ data.tar.gz: b227eb6e849c5b9971d8fd3e2cb10babc4d1dd702424149daad80eb5044ff945acc8422a522c958a5fd5492cc5727392a5fd6f787a4d7364b10a99d56a108ee7
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
4
3
  - 2.2.2
5
4
  - 2.3.0
6
5
  before_install:
@@ -82,6 +82,14 @@ module Dato
82
82
  entity.position
83
83
  end
84
84
 
85
+ def parent
86
+ @items_repo.find(entity.parent_id) if item_type.tree && entity.parent_id
87
+ end
88
+
89
+ def children
90
+ @items_repo.children_of(id) if item_type.tree
91
+ end
92
+
85
93
  def updated_at
86
94
  Time.parse(entity.updated_at).utc
87
95
  end
@@ -103,6 +111,16 @@ module Dato
103
111
 
104
112
  base[:position] = position if item_type.sortable
105
113
 
114
+ if item_type.tree
115
+ base[:position] = position
116
+ base[:children] = children.map do |_i|
117
+ value.to_hash(
118
+ max_depth,
119
+ current_depth + 1
120
+ )
121
+ end
122
+ end
123
+
106
124
  fields.each_with_object(base) do |field, result|
107
125
  value = send(field.api_key)
108
126
 
@@ -12,6 +12,7 @@ module Dato
12
12
  @entities_repo = entities_repo
13
13
  @collections_by_type = {}
14
14
  @items_by_id = {}
15
+ @items_by_parent_id = {}
15
16
  @item_type_methods = {}
16
17
 
17
18
  build_cache!
@@ -21,6 +22,10 @@ module Dato
21
22
  @items_by_id[id.to_s]
22
23
  end
23
24
 
25
+ def children_of(id)
26
+ @items_by_parent_id[id.to_s]
27
+ end
28
+
24
29
  def respond_to_missing?(method, include_private = false)
25
30
  if collections_by_type.key?(method)
26
31
  true
@@ -116,6 +121,11 @@ module Dato
116
121
  end
117
122
 
118
123
  @items_by_id[item.id] = item
124
+
125
+ if item_entity.respond_to?(:parent_id) && item_entity.parent_id
126
+ @items_by_parent_id[item_entity.parent_id] ||= []
127
+ @items_by_parent_id[item_entity.parent_id] << item
128
+ end
119
129
  end
120
130
 
121
131
  item_types.each do |item_type|
@@ -8,9 +8,9 @@ module Dato
8
8
  def create(resource_attributes)
9
9
  body = JsonApiSerializer.new(
10
10
  type: :item_type,
11
- attributes: %i(api_key name ordering_direction singleton sortable),
11
+ attributes: %i(api_key name ordering_direction singleton sortable tree),
12
12
  relationships: { ordering_field: { collection: false, type: :field } },
13
- required_attributes: %i(api_key name ordering_direction singleton sortable),
13
+ required_attributes: %i(api_key name ordering_direction singleton sortable tree),
14
14
  required_relationships: %i(ordering_field)
15
15
  ).serialize(resource_attributes)
16
16
 
@@ -20,9 +20,9 @@ module Dato
20
20
  def update(item_type_id, resource_attributes)
21
21
  body = JsonApiSerializer.new(
22
22
  type: :item_type,
23
- attributes: %i(api_key name ordering_direction singleton sortable),
23
+ attributes: %i(api_key name ordering_direction singleton sortable tree),
24
24
  relationships: { ordering_field: { collection: false, type: :field } },
25
- required_attributes: %i(api_key name ordering_direction singleton sortable),
25
+ required_attributes: %i(api_key name ordering_direction singleton sortable tree),
26
26
  required_relationships: %i(ordering_field)
27
27
  ).serialize(resource_attributes, item_type_id)
28
28
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Dato
3
- VERSION = '0.3.22'
3
+ VERSION = '0.3.23'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.22
4
+ version: 0.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler