본문 바로가기
[AWS]/GITLAB

45장. Anchors

by SAMSUNG CLOUD-OKY 2022. 2. 21.
반응형

 

## Anchors 활용
- 중복 콘텐츠 방지
- 다른 개체의 속성을 상속

 

 

 

 

https://codebeautify.org/yaml-to-json-xml-csv

 

Best Online YAML Converter - Convert YAML Strings into JSON, XML, CSV

 

codebeautify.org

 

 

 

======================================================

 

Yambo has a very nice feature called Anker's in the beginning, it does seem a bit weird to use it,

but in this lecture I would try to explain you what anchors are, how you can use them effectively.

And, yeah, hopefully this will work out.

So let's jump in to an example so that you can easily understand what I'm talking about in this very

simple person object that we have here, let's imagine that we have another property called a cell or

something like that.

And let's say all this property always has to be equal with what says on names of for example, the

name is John.

So, for example, the name is John, then this property needs to be John as well.

If I change it here to Jane, it should be Jane as well.

It maybe just doesn't make a lot of sense here, but just hang on for a second in order to avoid this

duplication.

Yamal provides this important feature called Angus, and which means we can sort of like define a value

and a value, and we do it by using the ampersand sign and defining an alias on just called alias name

here.

It's the same as the key here, but it doesn't have to be the same.

And now I have to find this alias here.

I can replace Jane here with asterisks in the name of the alias that I have selected in this case was

named.

So let's copy and paste this and go to our Yamal, to Jason Convertino and take a closer look at what

has happened.

So now I'm going to convert it to Jason and you will see here, that name is Gene and Self is Gene,

and I didn't have to duplicate this fellow.

So if I'm changing here to something else.

It has changed here as well, so this is a very important.

Feature of the language that allows us to do stuff like this, simply anchoring a property isn't really

that helpful.

You could use it, but usually it's not that powerful.

But I just wanted to start in a very, very small example so that you can have and understand exactly

how this works.

Let's go back and say that we maybe have multiple persons, which in this case is not the scenario.

But let's say we have to defined multiple persons and for whatever reason, they share some common properties.

So, for example, if I defined here based person.

We can say that.

Maybe the city and a country where they live is the same.

So.

City is New York City and country is USA, that's great.

Now we can use this object and have its values anchored just as we have with a single value, so we

can anchor an entire object, not only value.

And the way we do it is pretty, pretty similar.

So, for example, if I define my anchor here as base and I'm doing specifically not using the same

as the property name as an object name to show you that you can define any an alias that you want.

And now and go inside the person.

But it will have to do is to put in to less than Signe's.

Colin.

And then again, I only got access to the property.

And that one is space.

So what this will do is it will basically merge these two objects.

It will take the properties, city and country from base person, and it will add those properties to

person.

So, for example, if this was person one.

And I have another person that is called person two, for example, then in that scenario, this will

work and will not have a problem.

We will able to use that multiple times.

Now, I'm not going to use it.

I just wanted to show you how it works for this very simple example.

So back at the convertor.

And you will see here that no person has the same properties that were inherited from base person,

city and country.

And this is a very, very powerful feature that you will be using when building your get PMO pipelines

in order to reduce the amount of code.

What's important to remember about anchors is that it helps you avoid duplicate content across your

configurations and you can use anchors to sort of like inherit properties from other objects without

having to duplicate a lot of stuff.

 

 

 

반응형

'[AWS] > GITLAB' 카테고리의 다른 글

47. Overview (Deploy JAVA To AWS Elastic Beanstalk)  (0) 2022.02.21
46장. ​​작업 템플릿 만들기  (0) 2022.02.21
44. 작업 비활성화  (0) 2022.02.21
43장. YAML 이해하기  (1) 2022.02.21
42장. YAML Overview  (0) 2022.02.21

댓글