@@ -31,15 +31,13 @@ many cases you need to explicitly tell Terra what type you want to use.
31
31
A piece of data defined in a config is something we will call an
32
32
**object **. All objects can be categorized by having a type, which is
33
33
determined by how it is defined in the config. Config files always
34
- define a single object, which is what we will call the **top level
35
- object **.
34
+ define a single object.
36
35
37
36
Integers
38
37
--------
39
38
40
39
To put this information to use, let's create create a new config file in
41
- YAML and define our top level object. For our type let's use something
42
- called an ``Integer ``.
40
+ YAML. For our type let's use the ``Integer `` type.
43
41
44
42
Integers represent whole numbers and as such, are
45
43
written as whole numbers like so:
@@ -62,8 +60,7 @@ written as whole numbers like so:
62
60
63
61
42
64
62
65
- We have now created a config that defines an ``Integer `` as the top
66
- level object, which represents the number ``42 ``, simple right?
63
+ We have now created a config that defines an ``Integer ``, which represents the number ``42 ``.
67
64
68
65
Floats
69
66
------
@@ -194,15 +191,12 @@ By themselves, integers, floats, and strings aren't too useful, until we
194
191
start assigning labels to them. We can do that using a type called a
195
192
``Map ``.
196
193
197
- .. _key-value-pair :
194
+ - A map is a *collection of objects *.
195
+ - Each object in the collection is called a **value **.
196
+ - Each **value ** is identified by another object called a **key **.
198
197
199
- A map is a *collection of objects *, referred to individually as
200
- **values **, where each **value ** in the collection is identified by
201
- another unique object called a **key **. A key and a value together are
202
- called a **key-value pair **.
203
-
204
- Here we will make a new config where the *top level object * is of type
205
- ``Map ``, and both the *key * and *value * are of type ``String ``:
198
+ Here we will make a new config with type ``Map ``, and both the
199
+ key and value are of type ``String ``:
206
200
207
201
.. tab-set ::
208
202
@@ -224,7 +218,7 @@ Here we will make a new config where the *top level object* is of type
224
218
"this is a key" : " this is a value"
225
219
}
226
220
227
- Since maps are * collections * of objects, we can list multiple key value
221
+ Since maps are collections of objects, we can list multiple key value
228
222
pairs within the map like so:
229
223
230
224
.. tab-set ::
@@ -251,10 +245,33 @@ pairs within the map like so:
251
245
"meaning-of-life" : 42
252
246
}
253
247
254
- This is useful because as explained above, configs only contain *one *
255
- top level object. By using maps, we are capable of defining more than
256
- one object within a config, as well as being able to identify what each
257
- of those objects are using keys.
248
+ This is useful because as explained above, configs only contain one main object.
249
+ By using maps, we are capable of defining multiple objects within a map,
250
+ as well as being able to identify each of those objects with keys.
251
+
252
+ Each key within the same map must be unique, the following is invalid:
253
+
254
+ .. tab-set ::
255
+
256
+ .. tab-item :: YAML
257
+
258
+ .. code-block :: yaml
259
+ :caption : config.yml
260
+ :linenos :
261
+
262
+ duplicated key : value A
263
+ duplicated key : value B
264
+
265
+ .. tab-item :: JSON
266
+
267
+ .. code-block :: json
268
+ :caption: config.json
269
+ :linenos:
270
+
271
+ {
272
+ "duplicated key" : " value A" ,
273
+ "duplicated key" : " value B"
274
+ }
258
275
259
276
.. _map-ordering :
260
277
@@ -316,16 +333,12 @@ Lists
316
333
-----
317
334
318
335
In addition to maps, we can also use a type called a ``List `` to
319
- indicate a collection of data . Lists differ from maps in that each
320
- object (called an **item **) in a list is not assigned a unique key, but
321
- is instead identified by It's position in the list. Because of this,
336
+ define a collection of objects . Lists differ from maps in that each
337
+ **item ** (the term for an object in a list) is not assigned a unique key, but
338
+ is instead identified by its position in the list. Because of this,
322
339
*the order in which you define each object is significant *, unlike maps.
323
340
324
- Another thing to note is generally, every item contained within a list
325
- will be of the same type.
326
-
327
- Here is a config where the *top level object * is a ``List ``, which
328
- contains multiple ``String ``\ s:
341
+ Here is a config with type ``List ``, which contains multiple ``String ``\ s:
329
342
330
343
.. tab-set ::
331
344
@@ -354,7 +367,7 @@ contains multiple ``String``\ s:
354
367
Nesting Objects
355
368
===============
356
369
357
- Because values in maps and items in lists can be of any type, It 's
370
+ Because values in maps and items in lists can be of any type, it 's
358
371
possible to nest maps in maps, lists in lists, lists in maps, and so on.
359
372
360
373
.. tip ::
@@ -374,7 +387,7 @@ possible to nest maps in maps, lists in lists, lists in maps, and so on.
374
387
key : 42
375
388
376
389
Types that can span multiple lines, such as maps and lists won't fit
377
- on a single line. For example you man want the following map which spans
390
+ on a single line. For example you may want the following map which spans
378
391
multiple lines to be a value within another map:
379
392
380
393
.. code-block :: yaml
@@ -402,7 +415,7 @@ possible to nest maps in maps, lists in lists, lists in maps, and so on.
402
415
- item 1
403
416
- item 2
404
417
405
- Multiple ' levels of indentation' can be used, for example here is the prior map further
418
+ Multiple levels of indentation can be used, for example here is the prior map further
406
419
nested under (as the value for the key) ``qux ``:
407
420
408
421
.. code-block :: yaml
@@ -412,6 +425,10 @@ possible to nest maps in maps, lists in lists, lists in maps, and so on.
412
425
foo : a
413
426
bar : b
414
427
428
+ Each map can be visualized by drawing boxes like so:
429
+
430
+ .. image :: /img/config/development/nested-maps.png
431
+
415
432
.. tab-item :: JSON
416
433
417
434
Example of a ``Map `` defined in a ``Map ``:
@@ -453,7 +470,7 @@ For example the following is invalid:
453
470
key : foo
454
471
baz : bar
455
472
456
- The reason this is invalid is because there are two competing values being
473
+ This is invalid is because there are two competing values being
457
474
assigned to ``key ``, which are ``foo `` and the map containing ``baz: bar ``.
458
475
459
476
Deleting one of the values would make this valid YAML:
@@ -555,7 +572,7 @@ appointments using everything we have covered thus far:
555
572
]
556
573
}
557
574
558
- In this example, our top level object is of type ``Map ``, which contains
575
+ In this example, the config is of type ``Map ``, which contains
559
576
two keys ``shopping-list `` and ``appointments ``. The value of both keys
560
577
are of type ``List ``, where each *item * in each list contains a ``Map ``.
561
578
0 commit comments