Module: Jamf::BaseClass
- Defined in:
- lib/jamf/base_class.rb
Overview
This mixin should be extended in base class definitions it will raise an error if those classes are instantiated or allocated It also maintains an array of classes that extend themselves this way
Constant Summary collapse
- DEFAULT_ACTION =
'access the API'.freeze
- ALLOCATION_ACTION =
'be allocated'.freeze
- INSTANTIATION_ACTION =
'be instantiated'.freeze
Class Method Summary collapse
-
.base_classes ⇒ Object
Classes will be added to this array as they are exteded by BaseClass.
-
.extended(by_class) ⇒ Object
when a class is extended by this module, it gets added to the array of known base classes.
-
.stop_if_base_class(klass, action = DEFAULT_ACTION) ⇒ Object
raise an exception if a given class is a base class.
Instance Method Summary collapse
- #base_class? ⇒ Boolean
-
#new(*args, **kwargs, &block) ⇒ Object
Can’t instantiate if base_class.
-
#stop_if_base_class(action = DEFAULT_ACTION) ⇒ Object
raise an exception if this class is a base class.
Class Method Details
.base_classes ⇒ Object
Classes will be added to this array as they are exteded by BaseClass
27 28 29 |
# File 'lib/jamf/base_class.rb', line 27 def self.base_classes @base_classes ||= [] end |
.extended(by_class) ⇒ Object
when a class is extended by this module, it gets added to the array of known base classes
22 23 24 |
# File 'lib/jamf/base_class.rb', line 22 def self.extended(by_class) base_classes << by_class end |
.stop_if_base_class(klass, action = DEFAULT_ACTION) ⇒ Object
raise an exception if a given class is a base class
32 33 34 |
# File 'lib/jamf/base_class.rb', line 32 def self.stop_if_base_class(klass, action = DEFAULT_ACTION) raise Jamf::UnsupportedError, "#{klass} is a base class and cannot #{action}." if base_classes.include? klass end |
Instance Method Details
#base_class? ⇒ Boolean
36 37 38 |
# File 'lib/jamf/base_class.rb', line 36 def base_class? Jamf::BaseClass.base_classes.include? self end |
#new(*args, **kwargs, &block) ⇒ Object
Can’t instantiate if base_class
47 48 49 50 |
# File 'lib/jamf/base_class.rb', line 47 def new(*args, **kwargs, &block) stop_if_base_class INSTANTIATION_ACTION super(*args, **kwargs, &block) end |
#stop_if_base_class(action = DEFAULT_ACTION) ⇒ Object
raise an exception if this class is a base class
53 54 55 |
# File 'lib/jamf/base_class.rb', line 53 def stop_if_base_class(action = DEFAULT_ACTION) Jamf::BaseClass.stop_if_base_class self, action end |