Skip to content

Commit

Permalink
Created DumpRoot method in System/CommonMethods/Utils class.
Browse files Browse the repository at this point in the history
This is a new method which can then be included into the other methods using the Embedded method feature.
Created System/CommonMethods/Utils class.

#350

Changed name to LogObject and many other changes .....
Added documentation in the method
  • Loading branch information
billfitzgerald0120 committed Jul 27, 2018
1 parent 863c394 commit cf3591e
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
object_type: class
version: 1.0
object:
attributes:
description: Utility class for methods
display_name:
name: Utils
type:
inherits:
visibility:
owner:
schema:
- field:
aetype: method
name: common_meth
display_name:
datatype: string
priority: 1
owner:
default_value:
substitute: true
message: create
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries:
max_time:
- field:
aetype: relationship
name: common_rel
display_name:
datatype: string
priority: 2
owner:
default_value:
substitute: true
message: create
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries:
max_time:
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Description: Display Log messages for object attributes for root, current or desired object.
#

module ManageIQ
module Automate
module System
module CommonMethods
module Utils
class LogObject
# If you want to log the root MiqAeObject and use the global $evm
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.root
#
# If you want to log the root MiqAeObject and use a specific handle
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.root(handle)
#
def self.root(handle = $evm)
log(handle.root, "root", handle)
end

# If you want to log the current MiqAeObject and use the global $evm
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.current
#
# If you want to log the current MiqAeObject and use a specific handle
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.current(handle)
#
def self.current(handle = $evm)
log(handle.current, "current", handle)
end


# If you want to log a MiqAeObject and use the global $evm
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(vm)
# If you want to log a specific MiqAeObject with custom header and footer message
# This uses the global $evm
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(vm, "My Object")
# If you want to log a specific MiqAeObject with custom header and an handle from an
# instance method
# ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(vm, "My Object", @handle)

def self.log(obj, object_string = 'Automation Object', handle = $evm)
handle.log("info", "Listing #{object_string} Attributes - Begin")
obj.attributes.sort.each { |k, v| handle.log("info", " Attribute - #{k}: #{v}") }
handle.log("info", "Listing #{object_string} Attributes - End")
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
object_type: method
version: 1.0
object:
attributes:
name: log_object
display_name:
description:
scope: instance
language: ruby
location: inline
options: {}
inputs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require_domain_file
describe ManageIQ::Automate::System::CommonMethods::Utils::LogObject do
let(:user) { FactoryGirl.create(:user_with_email_and_group) }
let(:svc_model_user) { MiqAeMethodService::MiqAeServiceUser.find(user.id) }
let(:ems) { FactoryGirl.create(:ext_management_system) }

let(:root) do
Spec::Support::MiqAeMockObject.new(
'dialog_provider' => ems.id.to_s,
'user' => svc_model_user,
'current' => current_object
)
end

let(:current_object) { Spec::Support::MiqAeMockObject.new('a' => 1, 'b' => 2) }
let(:ae_service) do
Spec::Support::MiqAeMockService.new(root).tap do |service|
current_object.parent = root
service.current_object = current_object
current = current_object
end
end

let(:log_header_footer_count) { 2 }
let(:root_attr_count) { 3 }
let(:current_attr_count) { 2 }


it '.root' do
expect(ae_service).to receive(:log).with('info',/Listing root Attributes/).exactly(log_header_footer_count).times
expect(ae_service).to receive(:log).with('info',/ Attribute/).exactly(root_attr_count).times

# described_class.root(ae_service)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.root(ae_service)
end

it '.current' do
expect(ae_service).to receive(:log).with('info',/Listing current Attributes/).exactly(log_header_footer_count).times
expect(ae_service).to receive(:log).with('info',/ Attribute/).exactly(current_attr_count).times

# described_class.current(ae_service)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.current(ae_service)
end

it '.log' do
expect(ae_service).to receive(:log).with('info',/Listing My Object Attributes/).exactly(log_header_footer_count).times
expect(ae_service).to receive(:log).with('info',/ Attribute/).exactly(root_attr_count).times

# described_class.log(ae_service, root)
ManageIQ::Automate::System::CommonMethods::Utils::LogObject.log(root, 'My Object', ae_service)
end
end

0 comments on commit cf3591e

Please sign in to comment.