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.
This commit is contained in:
parent
90f460641e
commit
d6665e55ca
12 changed files with 539 additions and 8 deletions
26
lib/couchrest/more/property.rb
Normal file
26
lib/couchrest/more/property.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue