Class: AbideDevUtils::XCCDF::ObjectContainer
- Inherits:
-
Object
- Object
- AbideDevUtils::XCCDF::ObjectContainer
- Includes:
- Common
- Defined in:
- lib/abide_dev_utils/xccdf.rb
Constant Summary
Constants included from Common
Common::CIS_CONTROL_NUMBER, Common::CIS_CONTROL_PARTS, Common::CIS_LEVEL_CODE, Common::CIS_NEXT_GEN_WINDOWS, Common::CIS_PROFILE_PARTS, Common::CONTROL_PREFIX, Common::UNDERSCORED, Common::XPATHS
Instance Method Summary collapse
-
#initialize(list, object_creation_method, *args, **kwargs) ⇒ ObjectContainer
constructor
A new instance of ObjectContainer.
- #method_missing(m, *args, &block) ⇒ Object
- #respond_to_missing?(m, include_private = false) ⇒ Boolean
- #search(property, item) ⇒ Object
- #to_h ⇒ Object
Methods included from Common
#==, #abide_object?, #control_parts, #control_profile_text, #default_diff_opts, #diff, #name_normalize_control, #normalize_control_name, #normalize_profile_name, #normalize_string, #number_normalize_control, #profile_parts, #sorted_control_classes, #sorted_profile_classes, #text_normalize, #validate_xccdf, #xpath
Constructor Details
#initialize(list, object_creation_method, *args, **kwargs) ⇒ ObjectContainer
Returns a new instance of ObjectContainer.
465 466 467 468 |
# File 'lib/abide_dev_utils/xccdf.rb', line 465 def initialize(list, object_creation_method, *args, **kwargs) @object_list = send(object_creation_method.to_sym, list, *args, **kwargs) @searchable = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
470 471 472 473 474 475 476 |
# File 'lib/abide_dev_utils/xccdf.rb', line 470 def method_missing(m, *args, &block) property = m.to_s.start_with?('search_') ? m.to_s.split('_')[-1].to_sym : nil return search(property, *args, &block) if property && @searchable.include?(property) return @object_list.send(m, *args, &block) if @object_list.respond_to?(m) super end |
Instance Method Details
#respond_to_missing?(m, include_private = false) ⇒ Boolean
478 479 480 481 482 |
# File 'lib/abide_dev_utils/xccdf.rb', line 478 def respond_to_missing?(m, include_private = false) return true if m.to_s.start_with?('search_') && @searchable.include?(m.to_s.split('_')[-1].to_sym) super end |
#search(property, item) ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/abide_dev_utils/xccdf.rb', line 491 def search(property, item) max = @object_list.length - 1 min = 0 while min <= max mid = (min + max) / 2 return @object_list[mid] if @object_list[mid].send(property.to_sym) == item if @object_list[mid].send(property.to_sym) > item max = mid - 1 else min = mid + 1 end end nil end |
#to_h ⇒ Object
484 485 486 487 488 489 |
# File 'lib/abide_dev_utils/xccdf.rb', line 484 def to_h @object_list.each_with_object({}) do |obj, self_hash| key = resolve_hash_key(obj) self_hash[key] = obj.to_h end end |