couchrest_model/lib/couchrest/more/property.rb
Matt Aimonetti d6665e55ca Started on the ExtendedDocument class with features moved to mixins.
Properties got added, they define getters, setters and aliases.
They will also be the base of the new validation system.
2009-01-29 18:45:01 -08:00

26 lines
769 B
Ruby

module CouchRest
# Basic attribute support adding getter/setter + validation
class Property
attr_reader :name, :type, :validation_format, :required, :read_only, :alias
# attribute to define
def initialize(name, type = String, options = {})
@name = name.to_s
@type = type
parse_options(options)
self
end
private
def parse_options(options)
return if options.empty?
@required = true if (options[:required] && (options[:required] == true))
@validation_format = options[:format] if options[:format]
@read_only = options[:read_only] if options[:read_only]
@alias = options[:alias] if options
end
end
end