File tree Expand file tree Collapse file tree
lib/octocatalog-diff/util
spec/octocatalog-diff/tests/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # Handy methods that are not tied to one particular class
4+
5+ module OctocatalogDiff
6+ module Util
7+ # Helper class to construct catalogs, performing all necessary steps such as
8+ # bootstrapping directories, installing facts, and running puppet.
9+ class Util
10+ # Utility Method!
11+ # `is_a?(class)` only allows one method, but this uses an array
12+ # @param object [?] Object to consider
13+ # @param classes [Array] Classes to determine if object is a member of
14+ # @return [Boolean] True if object is_a any of the classes, false otherwise
15+ def self . object_is_any_of? ( object , classes )
16+ classes . each { |clazz | return true if object . is_a? clazz }
17+ false
18+ end
19+ end
20+ end
21+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require_relative '../spec_helper'
4+ require 'ostruct'
5+ require OctocatalogDiff ::Spec . require_path ( '/util/util' )
6+
7+ describe OctocatalogDiff ::Util ::Util do
8+ describe '#object_is_any_of?' do
9+ it 'should return true when object is one of the classes' do
10+ object = 42
11+ classes = [ Fixnum , Integer ]
12+ expect ( described_class . object_is_any_of? ( object , classes ) ) . to eq ( true )
13+ end
14+
15+ it 'should return false when object is not one of the classes' do
16+ object = :chickens
17+ classes = [ Fixnum , Integer ]
18+ expect ( described_class . object_is_any_of? ( object , classes ) ) . to eq ( false )
19+ end
20+ end
21+ end
You can’t perform that action at this time.
0 commit comments