Class: Bosh::Director::Models::DirectorAttribute
- Defined in:
- lib/bosh/director/models/director_attribute.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find_or_create_uuid(logger) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bosh/director/models/director_attribute.rb', line 7 def self.find_or_create_uuid(logger) uuid = first(name: 'uuid') if uuid logger.info("Found uuid director attribute with value=#{uuid.value.inspect}") return uuid.value end begin uuid = create(name: 'uuid', value: SecureRandom.uuid) logger.info("Created uuid director attribute with value=#{uuid.value.inspect}") uuid.value rescue Sequel::DatabaseError => e # Database will throw an error in case of race condition # causing multiple uuid records being inserted logger.info("Failed to create uuid director attribute e=#{e.inspect}\n#{e.backtrace}") uuid = first(name: 'uuid') logger.info("Found uuid director attribute with value=#{uuid.value.inspect}") uuid.value end end |
.update_or_create_uuid(value, logger) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/bosh/director/models/director_attribute.rb', line 29 def self.update_or_create_uuid(value, logger) if where(name: 'uuid').update(value: value) == 0 create(name: 'uuid', value: value) logger.info("Created uuid director attribute with value=#{value.inspect}") else logger.info("Updated uuid director attribute with value=#{value.inspect}") end value end |
Instance Method Details
#validate ⇒ Object
3 4 5 |
# File 'lib/bosh/director/models/director_attribute.rb', line 3 def validate validates_presence :name end |