26 lines
737 B
Ruby
26 lines
737 B
Ruby
module CouchRest
|
|
|
|
# Basic attribute support for adding getter/setter + validation
|
|
class Property
|
|
attr_reader :name, :type, :read_only, :alias, :options
|
|
|
|
# attribute to define
|
|
def initialize(name, type = nil, options = {})
|
|
@name = name.to_s
|
|
@type = type || String
|
|
parse_options(options)
|
|
self
|
|
end
|
|
|
|
|
|
private
|
|
def parse_options(options)
|
|
return if options.empty?
|
|
@validation_format = options.delete(:format) if options[:format]
|
|
@read_only = options.delete(:read_only) if options[:read_only]
|
|
@alias = options.delete(:alias) if options[:alias]
|
|
@options = options
|
|
end
|
|
|
|
end
|
|
end |