Module: Jamf::BaseClass
- Included in:
- CollectionResource, JSONObject, Prestage, Resource, SingletonResource
- Defined in:
- lib/jamf/api/mixins/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
-
#allocate(*args, &block) ⇒ Object
Can't allocate if base class.
- #base_class? ⇒ Boolean
-
#new(*args, &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
44 45 46 |
# File 'lib/jamf/api/mixins/base_class.rb', line 44 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
39 40 41 |
# File 'lib/jamf/api/mixins/base_class.rb', line 39 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
49 50 51 |
# File 'lib/jamf/api/mixins/base_class.rb', line 49 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
#allocate(*args, &block) ⇒ Object
Can't allocate if base class
58 59 60 61 |
# File 'lib/jamf/api/mixins/base_class.rb', line 58 def allocate(*args, &block) stop_if_base_class ALLOCATION_ACTION super end |
#base_class? ⇒ Boolean
53 54 55 |
# File 'lib/jamf/api/mixins/base_class.rb', line 53 def base_class? Jamf::BaseClass.base_classes.include? self end |
#new(*args, &block) ⇒ Object
Can't instantiate if base_class
64 65 66 67 |
# File 'lib/jamf/api/mixins/base_class.rb', line 64 def new(*args, &block) stop_if_base_class INSTANTIATION_ACTION super end |
#stop_if_base_class(action = DEFAULT_ACTION) ⇒ Object
raise an exception if this class is a base class
70 71 72 |
# File 'lib/jamf/api/mixins/base_class.rb', line 70 def stop_if_base_class(action = DEFAULT_ACTION) Jamf::BaseClass.stop_if_base_class self, action end |