Class: Module

Inherits:
Object show all
Defined in:
lib/sup.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) yaml_properties(*props)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sup.rb', line 31

def yaml_properties *props
  props = props.map { |p| p.to_s }
  vars = props.map { |p| "@#{p}" }
  klass = self
  path = klass.name.gsub(/::/, "/")
  
  klass.instance_eval do
    define_method(:to_yaml_properties) { vars }
    define_method(:to_yaml_type) { "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}" }
  end

  YAML.add_domain_type("#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}", path) do |type, val|
    klass.new(*props.map { |p| val[p] })
  end
end