Class: Flapjack::Data::Tag

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON, Extensions::Associations, Extensions::ShortName, Swagger::Blocks, Zermelo::Records::RedisSet
Defined in:
lib/flapjack/data/tag.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.jsonapi_associationsObject



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/flapjack/data/tag.rb', line 205

def self.jsonapi_associations
  unless instance_variable_defined?('@jsonapi_associations')
    @jsonapi_associations = {
      :checks => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
        :post => true, :get => true, :patch => true, :delete => true,
        :number => :multiple, :link => true, :includable => true,
        :descriptions => {
          :post => "Associate checks with this tag.",
          :get => "Returns all checks linked to this tag.",
          :patch => "Update the checks associated with this tag.",
          :delete => "Delete associations between checks and this tag."
        }
      ),
      :contacts => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
        :post => true, :get => true, :patch => true, :delete => true,
        :number => :multiple, :link => true, :includable => true,
        :descriptions => {
          :post => "Associate contacts with this tag.",
          :get => "Returns all contacts linked to this tag.",
          :patch => "Update the contacts associated with this tag.",
          :delete => "Delete associations between contacts and this tag."
        }
      ),
      :rules => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
        :post => true, :get => true, :patch => true, :delete => true,
        :number => :multiple, :link => true, :includable => true,
        :descriptions => {
          :post => "Associate rules with this tag.",
          :get => "Returns all rules linked to this tag.",
          :patch => "Update the rules associated with this tag.",
          :delete => "Delete associations between rules and this tag."
        }
      ),
      :scheduled_maintenances => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
        :get => true,
        :number => :multiple, :link => true, :includable => false,
        :type => 'scheduled_maintenance',
        :klass => Flapjack::Data::ScheduledMaintenance,
        :descriptions => {
          :get => "Returns all scheduled maintenance periods for " \
                  "checks linked to this tag; default sort order is " \
                  "newest first."
        }
      ),
      :states => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
        :get => true,
        :number => :multiple, :link => true, :includable => false,
        :type => 'state',
        :klass => Flapjack::Data::State,
        :descriptions => {
          :get => "Returns all state records for all checks linked to " \
                  "this tag; default sort order is newest first."
        }
      ),
      :unscheduled_maintenances => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
        :get => true,
        :number => :multiple, :link => true, :includable => false,
        :type => 'unscheduled_maintenance',
        :klass => Flapjack::Data::UnscheduledMaintenance,
        :descriptions => {
          :get => "Returns all unscheduled maintenance periods for " \
                  "checks linked to this tag; default sort order is " \
                  "newest first."
        }
      )
    }
    populate_association_data(@jsonapi_associations)
  end
  @jsonapi_associations
end

.jsonapi_methodsObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/flapjack/data/tag.rb', line 173

def self.jsonapi_methods
  @jsonapi_methods ||= {
    :post => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
      :attributes => [:name],
      :descriptions => {
        :singular => "Create a tag.",
        :multiple => "Create tags."
      }
    ),
    :get => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
      :attributes => [:name],
      :descriptions => {
        :singular => "Returns data for a tag.",
        :multiple => "Returns data for tags."
      }
    ),
    :patch => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
      :attributes => [:name],
      :descriptions => {
        :singular => "Update a tag.",
        :multiple => "Update tags."
      }
    ),
    :delete => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
      :descriptions => {
        :singular => "Delete a tag.",
        :multiple => "Delete tags."
      }
    )
  }
end

.swagger_included_classesObject



159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/flapjack/data/tag.rb', line 159

def self.swagger_included_classes
  # hack -- hardcoding for now
  [
    Flapjack::Data::Check,
    Flapjack::Data::Contact,
    Flapjack::Data::Medium,
    Flapjack::Data::Rule,
    Flapjack::Data::ScheduledMaintenance,
    Flapjack::Data::State,
    Flapjack::Data::Tag,
    Flapjack::Data::UnscheduledMaintenance
  ]
end

Instance Method Details

#scheduled_maintenancesObject



44
45
46
47
48
49
# File 'lib/flapjack/data/tag.rb', line 44

def scheduled_maintenances
  sm_assocs = self.checks.associations_for(:scheduled_maintenances).
    values

  Flapjack::Data::ScheduledMaintenance.intersect(:id => sm_assocs)
end

#statesObject



51
52
53
54
55
56
# File 'lib/flapjack/data/tag.rb', line 51

def states
  st_assocs = self.checks.associations_for(:states).
    values

  Flapjack::Data::State.intersect(:id => st_assocs)
end

#unscheduled_maintenancesObject



58
59
60
61
62
63
# File 'lib/flapjack/data/tag.rb', line 58

def unscheduled_maintenances
  usm_assocs = self.checks.associations_for(:unscheduled_maintenances).
    values

  Flapjack::Data::UnscheduledMaintenance.intersect(:id => usm_assocs)
end