Module: Katalyst::Healthcheck::Store::Attributes::ClassMethods

Defined in:
lib/katalyst/healthcheck/store/attributes.rb

Constant Summary collapse

@@attributes =
{}

Instance Method Summary collapse

Instance Method Details

#attribute(name, type = :string) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/katalyst/healthcheck/store/attributes.rb', line 17

def attribute(name, type = :string)
  name = name.to_s
  serializer = case type
               when :integer
                 IntegerAttribute
               when :datetime
                 DateTimeAttribute
               else
                 Attribute
               end
  define_method(name) { @@attributes[name].read(@attributes) }
  define_method("#{name}=") { |value| @@attributes[name].write(@attributes, value) }
  @@attributes[name] = serializer.new(name)
end