Class: InchCI::Store::DigestCodeObject

Inherits:
Object
  • Object
show all
Defined in:
lib/inch_ci/store.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code_object) ⇒ DigestCodeObject

Returns a new instance of DigestCodeObject.


214
215
216
217
# File 'lib/inch_ci/store.rb', line 214

def initialize(code_object)
  hash = attributes_for_code_object(code_object)
  @digest = Digest::SHA1.base64digest(hash.to_yaml)
end

Instance Attribute Details

#digestObject (readonly)

Returns the value of attribute digest


208
209
210
# File 'lib/inch_ci/store.rb', line 208

def digest
  @digest
end

Class Method Details

.call(*args) ⇒ Object


210
211
212
# File 'lib/inch_ci/store.rb', line 210

def self.call(*args)
  new(*args).digest
end

Instance Method Details

#attributes_for_code_object(object) ⇒ Object


219
220
221
222
223
224
225
# File 'lib/inch_ci/store.rb', line 219

def attributes_for_code_object(object)
  attributes = data_attributes(object)
  attributes['roles'] = object.code_object_roles.map do |role|
    attributes_for_code_object_role(role)
  end
  attributes
end

#attributes_for_code_object_role(role) ⇒ Object


227
228
229
230
231
# File 'lib/inch_ci/store.rb', line 227

def attributes_for_code_object_role(role)
  attributes = data_attributes(role)
  attributes['name'] = role.code_object_role_name.name
  attributes
end

#data_attributes(object) ⇒ Object

Returns all attributes except id, digest, created_at, updated_at and all attributes ending in *_id


236
237
238
239
240
# File 'lib/inch_ci/store.rb', line 236

def data_attributes(object)
  object.attributes.delete_if do |k,v|
    k =~ /^(created_at|updated_at|digest|id)$/ || k =~ /_id$/
  end
end