Class: Jamf::Criteriable::Criteria
- Defined in:
- lib/jamf/api/classic/api_objects/criteriable/criteria.rb
Overview
This class stores an array of Criterion instances and provides methods for working with them as a group.
APIObject subclasses that include Jamf::Criteriable have a :criteria attribute which holds one Criteria object.
Objects that contain Criteria objects need to
-
call ‘#container = self’ on their Criteria object when its created.
-
implement #should_update, which the Criteria object calls when it changes.
Both of those tasks are handled by the Jamf::Criteriable module and are mixed in when it’s included.
See Jamf::Criteriable for examples
Constant Summary collapse
- CRITERION_ATTRIBUTES =
Criterion instances we maintain need these attributes.s
i[priority and_or name search_type value].freeze
Instance Attribute Summary collapse
-
#container ⇒ Jamf::APIObject subclass
writeonly
A reference to the object containing these Criteria.
-
#criteria ⇒ Array
The group of Jamf::Criteriable::Criterion instances making up these Criteria.
Instance Method Summary collapse
-
#append_criterion(criterion) ⇒ void
Add a new criterion to the end of the criteria.
-
#clear ⇒ void
Remove all criterion objects.
-
#delete_criterion(priority) ⇒ void
Remove a criterion from the criteria.
-
#initialize(new_criteria = []) ⇒ Criteria
constructor
A new instance of Criteria.
-
#insert_criterion(_priority, criterion) ⇒ void
Add a new criterion to the middle of the criteria.
-
#prepend_criterion(criterion) ⇒ void
Add a new criterion to the beginning of the criteria.
-
#pretty_print_instance_variables ⇒ Array
Remove the various cached data from the instance_variables used to create pretty-print (pp) output.
-
#rest_xml ⇒ REXML::Element
private
The xml element for the criteria.
-
#set_criterion(priority, criterion) ⇒ void
Change the details of one specific criterion.
-
#set_priorities ⇒ void
Set the priorities of the @criteria to match their array indices.
Constructor Details
#initialize(new_criteria = []) ⇒ Criteria
Returns a new instance of Criteria.
62 63 64 65 66 67 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 62 def initialize(new_criteria = []) @criteria = [] # validates the param and fills @criteria self.criteria = new_criteria end |
Instance Attribute Details
#container=(value) ⇒ Jamf::APIObject subclass (writeonly)
Returns a reference to the object containing these Criteria.
57 58 59 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 57 def container=(value) @container = value end |
#criteria ⇒ Array
Returns the group of Jamf::Criteriable::Criterion instances making up these Criteria.
54 55 56 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 54 def criteria @criteria end |
Instance Method Details
#append_criterion(criterion) ⇒ void
This method returns an undefined value.
Add a new criterion to the end of the criteria
102 103 104 105 106 107 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 102 def append_criterion(criterion) criterion_ok? criterion criterion.priority = @criteria.length @criteria << criterion @container.should_update if @container end |
#clear ⇒ void
This method returns an undefined value.
Remove all criterion objects
90 91 92 93 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 90 def clear @criteria = [] @container.should_update if @container end |
#delete_criterion(priority) ⇒ void
This method returns an undefined value.
Remove a criterion from the criteria
146 147 148 149 150 151 152 153 154 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 146 def delete_criterion(priority) if @criteria[priority] raise Jamf::MissingDataError, "Criteria can't be empty" if @criteria.count == 1 @criteria.delete_at priority set_priorities end @container.should_update if @container end |
#insert_criterion(_priority, criterion) ⇒ void
This method returns an undefined value.
Add a new criterion to the middle of the criteria
132 133 134 135 136 137 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 132 def insert_criterion(_priority, criterion) criterion_ok? criterion @criteria.insert criterion[:priority], criterion set_priorities @container.should_update if @container end |
#prepend_criterion(criterion) ⇒ void
This method returns an undefined value.
Add a new criterion to the beginning of the criteria
116 117 118 119 120 121 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 116 def prepend_criterion(criterion) criterion_ok? criterion @criteria.unshift criterion set_priorities @container.should_update if @container end |
#pretty_print_instance_variables ⇒ Array
Remove the various cached data from the instance_variables used to create pretty-print (pp) output.
191 192 193 194 195 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 191 def pretty_print_instance_variables vars = instance_variables.sort vars.delete :@container vars end |
#rest_xml ⇒ REXML::Element
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This can’t be a private method for this class since container classes must call it
Returns the xml element for the criteria.
204 205 206 207 208 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 204 def rest_xml cr = REXML::Element.new 'criteria' @criteria.each { |c| cr << c.rest_xml } cr end |
#set_criterion(priority, criterion) ⇒ void
This method returns an undefined value.
Change the details of one specific criterion
167 168 169 170 171 172 173 174 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 167 def set_criterion(priority, criterion) raise Jamf::NoSuchItemError, "No current criterion with priority '#{priority}'" unless @criteria[priority] criterion_ok? criterion @criteria[priority] = criterion set_priorities @container.should_update if @container end |
#set_priorities ⇒ void
This method returns an undefined value.
Set the priorities of the @criteria to match their array indices
181 182 183 |
# File 'lib/jamf/api/classic/api_objects/criteriable/criteria.rb', line 181 def set_priorities @criteria.each_index { |ci| @criteria[ci].priority = ci } end |