Class: Ripple::Property
Overview
Encapsulates a single property on your Ripple::Document class.
Instance Attribute Summary (collapse)
-
- (Symbol) key
readonly
The key of this property in the Document.
-
- (Hash) options
readonly
Configuration options.
-
- (Class) type
readonly
The Ruby type of property.
Instance Method Summary (collapse)
-
- (Object) default
The default value for this property if defined, or nil.
-
- (Property) initialize(key, type, options = {})
constructor
Create a new document property.
-
- (Object) type_cast(value)
Attempt to coerce the passed value into this property’s type.
-
- (Hash) validation_options
Options appropriate for the validates class method.
Constructor Details
- (Property) initialize(key, type, options = {})
Create a new document property.
55 56 57 58 59 |
# File 'ripple/lib/ripple/properties.rb', line 55 def initialize(key, type, ={}) @options = . @key = key.to_sym @type = type end |
Instance Attribute Details
- (Symbol) key (readonly)
The key of this property in the Document
44 45 46 |
# File 'ripple/lib/ripple/properties.rb', line 44 def key @key end |
- (Hash) options (readonly)
Configuration options
48 49 50 |
# File 'ripple/lib/ripple/properties.rb', line 48 def @options end |
- (Class) type (readonly)
The Ruby type of property.
46 47 48 |
# File 'ripple/lib/ripple/properties.rb', line 46 def type @type end |
Instance Method Details
- (Object) default
The default value for this property if defined, or nil.
62 63 64 65 66 67 |
# File 'ripple/lib/ripple/properties.rb', line 62 def default default = [:default] return nil if default.nil? type_cast(default.respond_to?(:call) ? default.call : default) end |
- (Object) type_cast(value)
Attempt to coerce the passed value into this property’s type
78 79 80 81 82 83 84 |
# File 'ripple/lib/ripple/properties.rb', line 78 def type_cast(value) if @type.respond_to?(:ripple_cast) @type.ripple_cast(value) else value end end |
- (Hash) validation_options
Options appropriate for the validates class method
70 71 72 |
# File 'ripple/lib/ripple/properties.rb', line 70 def @options.dup.except(:default) end |