Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ruby-liudesk-cmdb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LiU IT - Infrastructure
ruby-liudesk-cmdb
Commits
e7beb2c2
Verified
Commit
e7beb2c2
authored
1 year ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
Separate model data conversion methods
This allows storing the data in its expected format outside of CMDB calls
parent
60446fef
No related branches found
No related tags found
No related merge requests found
Pipeline
#101568
passed
1 year ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/liudesk_cmdb/model.rb
+32
-20
32 additions, 20 deletions
lib/liudesk_cmdb/model.rb
with
32 additions
and
20 deletions
lib/liudesk_cmdb/model.rb
+
32
−
20
View file @
e7beb2c2
...
@@ -128,6 +128,36 @@ module LiudeskCMDB
...
@@ -128,6 +128,36 @@ module LiudeskCMDB
superclass
.
fields
.
merge
(
@fields
||
{})
superclass
.
fields
.
merge
(
@fields
||
{})
end
end
def
convert_cmdb_to_ruby
(
data
)
fields
.
each
do
|
key
,
attributes
|
next
unless
data
[
key
]
case
attributes
[
:convert
].
to_s
when
Time
.
to_s
data
[
key
]
=
Time
.
parse
(
data
[
key
]).
round
when
Symbol
.
to_s
data
[
key
]
=
data
[
key
].
to_sym
end
end
data
end
def
convert_ruby_to_cmdb
(
data
)
fields
.
each
do
|
key
,
attributes
|
next
unless
data
.
key?
key
case
attributes
[
:convert
].
to_s
when
Time
.
to_s
data
[
key
]
=
data
[
key
].
utc
.
round
.
strftime
(
"%FT%T.%LZ"
)
if
data
[
key
].
is_a?
Time
when
Symbol
.
to_s
data
[
key
]
=
data
[
key
].
to_s
if
data
[
key
].
is_a?
Symbol
end
end
data
end
protected
protected
def
read_fields
(
*
fields
)
def
read_fields
(
*
fields
)
...
@@ -266,16 +296,7 @@ module LiudeskCMDB
...
@@ -266,16 +296,7 @@ module LiudeskCMDB
data
=
data
.
dup
data
=
data
.
dup
write_fields
=
self
.
class
.
fields
.
select
{
|
_
,
field
|
field
[
:access
].
to_s
.
end_with?
(
"write"
)
}.
map
{
|
k
,
_
|
k
}
write_fields
=
self
.
class
.
fields
.
select
{
|
_
,
field
|
field
[
:access
].
to_s
.
end_with?
(
"write"
)
}.
map
{
|
k
,
_
|
k
}
self
.
class
.
fields
.
each
do
|
key
,
attributes
|
self
.
class
.
convert_ruby_to_cmdb
(
data
)
next
unless
data
.
key?
key
case
attributes
[
:convert
].
to_s
when
Time
.
to_s
data
[
key
]
=
data
[
key
].
utc
.
round
.
strftime
(
"%FT%T.%LZ"
)
if
data
[
key
].
is_a?
Time
when
Symbol
.
to_s
data
[
key
]
=
data
[
key
].
to_s
if
data
[
key
].
is_a?
Symbol
end
end
data
.
select
{
|
k
,
_
|
write_fields
.
include?
(
k
)
}.
transform_keys
{
|
k
|
self
.
class
.
fields
.
dig
(
k
,
:name
)
}
data
.
select
{
|
k
,
_
|
write_fields
.
include?
(
k
)
}.
transform_keys
{
|
k
|
self
.
class
.
fields
.
dig
(
k
,
:name
)
}
end
end
...
@@ -291,16 +312,7 @@ module LiudeskCMDB
...
@@ -291,16 +312,7 @@ module LiudeskCMDB
@data
=
{}
unless
merge
@data
=
{}
unless
merge
@data
.
merge!
(
converted
)
@data
.
merge!
(
converted
)
self
.
class
.
fields
.
each
do
|
key
,
attributes
|
self
.
class
.
convert_cmdb_to_ruby
(
@data
)
next
unless
@data
[
key
]
case
attributes
[
:convert
].
to_s
when
Time
.
to_s
@data
[
key
]
=
Time
.
parse
(
@data
[
key
]).
round
when
Symbol
.
to_s
@data
[
key
]
=
@data
[
key
].
to_sym
end
end
@retrieved
=
Time
.
now
@retrieved
=
Time
.
now
self
self
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment