Class: Katalyst::Healthcheck::Store::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/katalyst/healthcheck/store/attributes.rb

Direct Known Subclasses

DateTimeAttribute, IntegerAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Attribute

Returns a new instance of Attribute.



53
54
55
# File 'lib/katalyst/healthcheck/store/attributes.rb', line 53

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



51
52
53
# File 'lib/katalyst/healthcheck/store/attributes.rb', line 51

def key
  @key
end

Instance Method Details

#read(attributes) ⇒ Object



57
58
59
# File 'lib/katalyst/healthcheck/store/attributes.rb', line 57

def read(attributes)
  deserialize(attributes[key]) if attributes.has_key?(key)
end

#write(attributes, value) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/katalyst/healthcheck/store/attributes.rb', line 61

def write(attributes, value)
  if value.nil?
    attributes.delete(key)
  elsif value.is_a?(String) # support already serialized values
    attributes[key] = value
  else
    attributes[key] = serialize(value)
  end
end