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" ...@@ -6,9 +6,9 @@ require "net/http"
require "time" require "time"
require_relative "liudesk_cmdb/version" require_relative "liudesk_cmdb/version"
require_relative "liudesk_cmdb/util"
require_relative "liudesk_cmdb/client" require_relative "liudesk_cmdb/client"
require_relative "liudesk_cmdb/model" require_relative "liudesk_cmdb/model"
require_relative "liudesk_cmdb/util"
# Base module for Liudesk CMDB # Base module for Liudesk CMDB
module LiudeskCMDB module LiudeskCMDB
......
...@@ -56,8 +56,6 @@ module LiudeskCMDB ...@@ -56,8 +56,6 @@ module LiudeskCMDB
end end
class << self class << self
attr_reader :fields
def create(client, **data) def create(client, **data)
new(client, **data).create new(client, **data).create
end end
...@@ -115,6 +113,12 @@ module LiudeskCMDB ...@@ -115,6 +113,12 @@ module LiudeskCMDB
@identifier @identifier
end end
def fields
return @fields || {} unless superclass <= Model
superclass.fields.merge(@fields || {})
end
protected protected
def read_fields(*fields) def read_fields(*fields)
...@@ -157,6 +161,11 @@ module LiudeskCMDB ...@@ -157,6 +161,11 @@ module LiudeskCMDB
end end
end end
read_fields :created_date, :updated_date, :archived
field_attributes :created_date, convert: Time
field_attributes :updated_date, convert: Time
def create def create
data = client.post(self.class.api_url, self.class.model_version, data_for_write(all: true)) data = client.post(self.class.api_url, self.class.model_version, data_for_write(all: true))
load_data(JSON.parse(data)) load_data(JSON.parse(data))
......
...@@ -9,7 +9,7 @@ module LiudeskCMDB::Models ...@@ -9,7 +9,7 @@ module LiudeskCMDB::Models
identifier :guid identifier :guid
supports_search supports_search
read_fields :guid, :created_date, :updated_date, :name, :archived read_fields :guid, :name
access_fields \ access_fields \
:division, :asset_owner, :status, :stolen, :division, :asset_owner, :status, :stolen,
:capital_equipment_id, :capital_object_id, :supplier, :supplier_article_number, :capital_equipment_id, :capital_object_id, :supplier, :supplier_article_number,
...@@ -19,8 +19,6 @@ module LiudeskCMDB::Models ...@@ -19,8 +19,6 @@ module LiudeskCMDB::Models
:bios_uuid, :external_documentation_link, :group_or_lab, :contact_information, :misc_information :bios_uuid, :external_documentation_link, :group_or_lab, :contact_information, :misc_information
field_attributes :hostname, name: "hostName" 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 :purchase_date, convert: Time
field_attributes :delivery_date, convert: Time field_attributes :delivery_date, convert: Time
field_attributes :warranty_enddate, convert: Time field_attributes :warranty_enddate, convert: Time
......
...@@ -20,7 +20,6 @@ module LiudeskCMDB::Models ...@@ -20,7 +20,6 @@ module LiudeskCMDB::Models
identifier :hostname identifier :hostname
read_fields :created_date, :updated_date, :archived
access_fields \ access_fields \
:hostname, :division, :asset_owner, :certificate_information, :hostname, :division, :asset_owner, :certificate_information,
:network_access_role, :hardware_id, :network_access_role, :hardware_id,
...@@ -31,8 +30,6 @@ module LiudeskCMDB::Models ...@@ -31,8 +30,6 @@ module LiudeskCMDB::Models
field_attributes :hostname, name: "hostName" field_attributes :hostname, name: "hostName"
field_attributes :hardware_id, name: "hardwareID" field_attributes :hardware_id, name: "hardwareID"
field_attributes :active_directory_ou, name: "activeDirectoryOU" 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 :operating_system_install_date, convert: Time
field_attributes :ad_creation_date, convert: Time field_attributes :ad_creation_date, convert: Time
......
...@@ -8,7 +8,6 @@ module LiudeskCMDB::Models ...@@ -8,7 +8,6 @@ module LiudeskCMDB::Models
identifier :hostname identifier :hostname
read_fields :created_date, :updated_date, :archived
access_fields \ access_fields \
:hostname, :division, :asset_owner, :certificate_information, :hostname, :division, :asset_owner, :certificate_information,
:network_access_role, :hardware_id, :network_access_role, :hardware_id,
...@@ -19,8 +18,6 @@ module LiudeskCMDB::Models ...@@ -19,8 +18,6 @@ module LiudeskCMDB::Models
field_attributes :hostname, name: "hostName" field_attributes :hostname, name: "hostName"
field_attributes :hardware_id, name: "hardwareID" field_attributes :hardware_id, name: "hardwareID"
field_attributes :active_directory_ou, name: "activeDirectoryOU" 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 :operating_system_install_date, convert: Time
field_attributes :ad_creation_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