diff --git a/lib/liudesk_cmdb.rb b/lib/liudesk_cmdb.rb index 98fbfd1982bbcccd24139616fbee118366fabe97..3e0ad142ab6786e6f0a99924041f7f32f40b7096 100644 --- a/lib/liudesk_cmdb.rb +++ b/lib/liudesk_cmdb.rb @@ -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 diff --git a/lib/liudesk_cmdb/model.rb b/lib/liudesk_cmdb/model.rb index 972822d614f2cd10e9b05b9309b4ab41a518a808..371ec36d0e8a150c3ec2edba158a5b07dd3d80a2 100644 --- a/lib/liudesk_cmdb/model.rb +++ b/lib/liudesk_cmdb/model.rb @@ -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)) diff --git a/lib/liudesk_cmdb/models/hardware.rb b/lib/liudesk_cmdb/models/hardware.rb index 3fd3ac481718d3e7a58e3b92d1b2a70777849beb..4335f0ab83ea58735b9aa83df36ab2194ace4a4d 100644 --- a/lib/liudesk_cmdb/models/hardware.rb +++ b/lib/liudesk_cmdb/models/hardware.rb @@ -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 diff --git a/lib/liudesk_cmdb/models/linux_client.rb b/lib/liudesk_cmdb/models/linux_client.rb index d2e5d5854e7b030c3da3a95b8de927d371422714..8ced5f52625cc47365c21882e0170844072aa757 100644 --- a/lib/liudesk_cmdb/models/linux_client.rb +++ b/lib/liudesk_cmdb/models/linux_client.rb @@ -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 diff --git a/lib/liudesk_cmdb/models/server.rb b/lib/liudesk_cmdb/models/server.rb index 9a8ac464a48229cd0f2086cc56c4e9cbd03a4a0d..78f21ea5cb351d11010a99ad67061a6a7f78edb4 100644 --- a/lib/liudesk_cmdb/models/server.rb +++ b/lib/liudesk_cmdb/models/server.rb @@ -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