Class: SupportOps::GitLab::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/support_ops_gitlab/gitlab/base.rb

Overview

Defines the class Base within the module SupportOps::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, client = nil) ⇒ Base

Returns a new instance of Base.

Since:

  • 1.0.0



40
41
42
43
44
45
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 40

def initialize(attributes = {}, client = nil)
  @client = client
  @original_attributes = {}
  set_attributes(attributes)
  store_original_attributes
end

Class Method Details

.attributesObject

Since:

  • 1.0.0



29
30
31
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 29

def attributes
  @attributes || []
end

.clientObject

Since:

  • 1.0.0



14
15
16
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 14

def client
  Configuration.config.client
end

.configure {|Configuration.config| ... } ⇒ Object

Yields:

Since:

  • 1.0.0



18
19
20
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 18

def configure
  yield Configuration.config
end

.define_attributes(*attrs) ⇒ Object

Since:

  • 1.0.0



22
23
24
25
26
27
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 22

def define_attributes(*attrs)
  @attributes = attrs
  attrs.each do |attr|
    attr_accessor attr
  end
end

.readonly_attributes(*attrs) ⇒ Object

Since:

  • 1.0.0



33
34
35
36
37
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 33

def readonly_attributes(*attrs)
  return @readonly_attributes || [] if attrs.empty?

  @readonly_attributes = attrs
end

.to_hash(object) ⇒ Hash

Converts an Object to a Hash

Parameters:

  • object (Object)

Returns:

  • (Hash)

Author:

  • Jason Colyer

Since:

  • 1.0.0



61
62
63
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 61

def self.to_hash(object)
  Hash[object.instance_variables.map { |name| [name.to_s[1..-1], object.instance_variable_get(name)] }]
end

Instance Method Details

#activate!Object

Since:

  • 1.0.0



187
188
189
190
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 187

def activate!
  re_client_present!
  activate_record
end

#approve!Object

Since:

  • 1.0.0



172
173
174
175
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 172

def approve!
  ensure_client_present!
  approve_record
end

#badgesObject

Since:

  • 1.0.0



235
236
237
238
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 235

def badges
  ensure_client_present!
  badges_record
end

#ban!Object

Since:

  • 1.0.0



162
163
164
165
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 162

def ban!
  ensure_client_present!
  ban_record
end

#block!Object

Since:

  • 1.0.0



152
153
154
155
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 152

def block!
  ensure_client_present!
  block_record
end

#client=(new_client) ⇒ Object

Since:

  • 1.0.0



320
321
322
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 320

def client=(new_client)
  @client = new_client
end

#commitsObject

Since:

  • 1.0.0



305
306
307
308
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 305

def commits
  ensure_client_present!
  commits_record
end

#contributorsObject

Since:

  • 1.0.0



310
311
312
313
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 310

def contributors
  ensure_client_present!
  contributors_record
end

#create_support_pin!Object

Since:

  • 1.0.0



202
203
204
205
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 202

def create_support_pin!
  ensure_client_present!
  create_support_pin_record
end

#deactivate!Object

Since:

  • 1.0.0



182
183
184
185
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 182

def deactivate!
  re_client_present!
  deactivate_record
end

#delete!Object

Since:

  • 1.0.0



97
98
99
100
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 97

def delete!
  ensure_client_present!
  delete_record
end

#diffsObject

Since:

  • 1.0.0



315
316
317
318
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 315

def diffs
  ensure_client_present!
  diffs_record
end

#disable_2fa!Object

Since:

  • 1.0.0



207
208
209
210
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 207

def disable_2fa!
  ensure_client_present!
  disable_2fa_record
end

#discussionsObject

Since:

  • 1.0.0



270
271
272
273
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 270

def discussions
  ensure_client_present!
  discussions_record
end

#emailsObject

Since:

  • 1.0.0



192
193
194
195
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 192

def emails
  ensure_client_present!
  emails_record
end

#encoded_pathObject

Since:

  • 1.0.0



227
228
229
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 227

def encoded_path
  encoded_path_record
end

#eventsObject

Since:

  • 1.0.0



295
296
297
298
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 295

def events
  ensure_client_present!
  events_record
end

#findObject

Since:

  • 1.0.0



65
66
67
68
69
70
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 65

def find
  ensure_client_present!
  set_attributes(get_record)
  store_original_attributes
  self
end

#find!Object

Since:

  • 1.0.0



72
73
74
75
76
77
78
79
80
81
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 72

def find!
  ensure_client_present!
  attrs = get_record
  if attrs == nil
    raise "Unable to locate #{self.class.name.demodulize.singularize.downcase} '#{self.id}'"
  end
  set_attributes(attrs)
  store_original_attributes
  self
end

#gpg_keysObject

Since:

  • 1.0.0



132
133
134
135
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 132

def gpg_keys
  ensure_client_present!
  gpg_keys_record
end

#hard_delete!Object

Since:

  • 1.0.0



102
103
104
105
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 102

def hard_delete!
  ensure_client_present!
  hard_delete_record
end

#impersonationsObject

Since:

  • 1.0.0



147
148
149
150
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 147

def impersonations
  ensure_client_present!
  impersonations_record
end

#issuesObject

Since:

  • 1.0.0



240
241
242
243
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 240

def issues
  ensure_client_present!
  issues_record
end

#jobsObject

Since:

  • 1.0.0



290
291
292
293
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 290

def jobs
  ensure_client_present!
  jobs_record
end

#latest_pipelineObject

Since:

  • 1.0.0



280
281
282
283
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 280

def latest_pipeline
  ensure_client_present!
  latest_pipeline_record
end

#members(**args) ⇒ Object

Since:

  • 1.0.0



222
223
224
225
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 222

def members(**args)
  ensure_client_present!
  members_record(**args)
end

#membershipsObject

Since:

  • 1.0.0



122
123
124
125
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 122

def memberships
  ensure_client_present!
  memberships_record
end

#merge_requestsObject

Since:

  • 1.0.0



245
246
247
248
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 245

def merge_requests
  ensure_client_present!
  merge_requests_record
end

#move!Object

Since:

  • 1.0.0



250
251
252
253
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 250

def move!
  ensure_client_present!
  move_record
end

#notesObject

Since:

  • 1.0.0



265
266
267
268
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 265

def notes
  ensure_client_present!
  notes_record
end

#paid?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



231
232
233
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 231

def paid?
  is_paid_record
end

#patsObject

Since:

  • 1.0.0



142
143
144
145
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 142

def pats
  ensure_client_present!
  pats_records
end

#pipeline_variablesObject

Since:

  • 1.0.0



285
286
287
288
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 285

def pipeline_variables
  ensure_client_present!
  pipeline_variables_record
end

#pipelinesObject

Since:

  • 1.0.0



275
276
277
278
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 275

def pipelines
  ensure_client_present!
  pipelines_record
end

#preferencesObject

Since:

  • 1.0.0



112
113
114
115
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 112

def preferences
  ensure_client_present!
  preferences_record
end

#projectsObject

Since:

  • 1.0.0



117
118
119
120
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 117

def projects
  ensure_client_present!
  projects_record
end

#reject!Object

Since:

  • 1.0.0



177
178
179
180
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 177

def reject!
  ensure_client_present!
  reject_record
end

#revoke!Object

Since:

  • 1.0.0



217
218
219
220
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 217

def revoke!
  ensure_client_present!
  revoke_record
end

#rotate!Object

Since:

  • 1.0.0



212
213
214
215
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 212

def rotate!
  ensure_client_present!
  rotate_record
end

#save!Object

Since:

  • 1.0.0



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 83

def save!
  ensure_client_present!
  new_data = if id.nil?
               create_record
             else
               update_record
             end
  new_data.each do |key, value|
    self.instance_variable_set("@#{key}", value) if self.respond_to?("#{key}=")
  end
  store_original_attributes
  self
end

#ssh_keysObject

Since:

  • 1.0.0



127
128
129
130
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 127

def ssh_keys
  ensure_client_present!
  ssh_keys_record
end

#statusObject

Since:

  • 1.0.0



107
108
109
110
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 107

def status
  ensure_client_present!
  status_record
end

#store_original_attributesObject

Since:

  • 1.0.0



47
48
49
50
51
52
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 47

def store_original_attributes
  @original_attributes = {}
  self.class.attributes.each do |attr|
    @original_attributes[attr] = instance_variable_get("@#{attr}")
  end
end

#subscribe!Object

Since:

  • 1.0.0



255
256
257
258
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 255

def subscribe!
  ensure_client_present!
  subscribe_record
end

#support_pinObject

Since:

  • 1.0.0



197
198
199
200
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 197

def support_pin
  ensure_client_present!
  support_pin_record
end

#tokensObject

Since:

  • 1.0.0



137
138
139
140
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 137

def tokens
  ensure_client_present!
  tokens_record
end

#unban!Object

Since:

  • 1.0.0



167
168
169
170
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 167

def unban!
  ensure_client_present!
  unban_record
end

#unblock!Object

Since:

  • 1.0.0



157
158
159
160
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 157

def unblock!
  ensure_client_present!
  unblock_record
end

#unsubscribe!Object

Since:

  • 1.0.0



260
261
262
263
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 260

def unsubscribe!
  ensure_client_present!
  unsubscribe_record
end

#webhooksObject

Since:

  • 1.0.0



300
301
302
303
# File 'lib/support_ops_gitlab/gitlab/base.rb', line 300

def webhooks
  ensure_client_present!
  webhooks_record
end