Skip to content
Snippets Groups Projects
Verified Commit e6bd3253 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Handle inherited fields correctly

parent 7bf8c230
No related branches found
No related tags found
No related merge requests found
Pipeline #100404 failed
......@@ -6,9 +6,9 @@ require "net/http"
require "time"
require_relative "liudesk_cmdb/version"
require_relative "liudesk_cmdb/util"
require_relative "liudesk_cmdb/client"
require_relative "liudesk_cmdb/model"
require_relative "liudesk_cmdb/util"
# Base module for Liudesk CMDB
module LiudeskCMDB
......
......@@ -56,8 +56,6 @@ module LiudeskCMDB
end
class << self
attr_reader :fields
def create(client, **data)
new(client, **data).create
end
......@@ -115,6 +113,12 @@ module LiudeskCMDB
@identifier
end
def fields
return @fields || {} unless superclass <= Model
superclass.fields.merge(@fields || {})
end
protected
def read_fields(*fields)
......@@ -157,6 +161,11 @@ module LiudeskCMDB
end
end
read_fields :created_date, :updated_date, :archived
field_attributes :created_date, convert: Time
field_attributes :updated_date, convert: Time
def create
data = client.post(self.class.api_url, self.class.model_version, data_for_write(all: true))
load_data(JSON.parse(data))
......
......@@ -9,7 +9,7 @@ module LiudeskCMDB::Models
identifier :guid
supports_search
read_fields :guid, :created_date, :updated_date, :name, :archived
read_fields :guid, :name
access_fields \
:division, :asset_owner, :status, :stolen,
:capital_equipment_id, :capital_object_id, :supplier, :supplier_article_number,
......@@ -19,8 +19,6 @@ module LiudeskCMDB::Models
:bios_uuid, :external_documentation_link, :group_or_lab, :contact_information, :misc_information
field_attributes :hostname, name: "hostName"
field_attributes :created_date, convert: Time
field_attributes :updated_date, convert: Time
field_attributes :purchase_date, convert: Time
field_attributes :delivery_date, convert: Time
field_attributes :warranty_enddate, convert: Time
......
......@@ -20,7 +20,6 @@ module LiudeskCMDB::Models
identifier :hostname
read_fields :created_date, :updated_date, :archived
access_fields \
:hostname, :division, :asset_owner, :certificate_information,
:network_access_role, :hardware_id,
......@@ -31,8 +30,6 @@ module LiudeskCMDB::Models
field_attributes :hostname, name: "hostName"
field_attributes :hardware_id, name: "hardwareID"
field_attributes :active_directory_ou, name: "activeDirectoryOU"
field_attributes :created_date, convert: Time
field_attributes :updated_date, convert: Time
field_attributes :operating_system_install_date, convert: Time
field_attributes :ad_creation_date, convert: Time
......
......@@ -8,7 +8,6 @@ module LiudeskCMDB::Models
identifier :hostname
read_fields :created_date, :updated_date, :archived
access_fields \
:hostname, :division, :asset_owner, :certificate_information,
:network_access_role, :hardware_id,
......@@ -19,8 +18,6 @@ module LiudeskCMDB::Models
field_attributes :hostname, name: "hostName"
field_attributes :hardware_id, name: "hardwareID"
field_attributes :active_directory_ou, name: "activeDirectoryOU"
field_attributes :created_date, convert: Time
field_attributes :updated_date, convert: Time
field_attributes :operating_system_install_date, convert: Time
field_attributes :ad_creation_date, convert: Time
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment