Class: MongoModel::Properties::Property
- Inherits:
-
Object
- Object
- MongoModel::Properties::Property
- Defined in:
- lib/mongomodel/concerns/properties.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as ⇒ Object
- #default(instance) ⇒ Object
- #embeddable? ⇒ Boolean
-
#initialize(name, type, options = {}) ⇒ Property
constructor
A new instance of Property.
- #internal? ⇒ Boolean
- #validate? ⇒ Boolean
Constructor Details
#initialize(name, type, options = {}) ⇒ Property
Returns a new instance of Property.
48 49 50 |
# File 'lib/mongomodel/concerns/properties.rb', line 48 def initialize(name, type, ={}) @name, @type, @options = name.to_sym, type, end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/mongomodel/concerns/properties.rb', line 46 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
46 47 48 |
# File 'lib/mongomodel/concerns/properties.rb', line 46 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
46 47 48 |
# File 'lib/mongomodel/concerns/properties.rb', line 46 def type @type end |
Instance Method Details
#==(other) ⇒ Object
73 74 75 |
# File 'lib/mongomodel/concerns/properties.rb', line 73 def ==(other) other.is_a?(self.class) && name == other.name && type == other.type && == other. end |
#as ⇒ Object
52 53 54 |
# File 'lib/mongomodel/concerns/properties.rb', line 52 def as [:as] || name.to_s end |
#default(instance) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mongomodel/concerns/properties.rb', line 56 def default(instance) if .key?(:default) default = [:default] if default.is_a?(Proc) case default.arity when 0 then instance.instance_exec(&default) else instance.instance_exec(instance, &default) end else default.duplicable? ? default.dup : default end elsif type.respond_to?(:mongomodel_default) type.mongomodel_default(instance) end end |
#embeddable? ⇒ Boolean
77 78 79 |
# File 'lib/mongomodel/concerns/properties.rb', line 77 def type.ancestors.include?(EmbeddedDocument) end |
#internal? ⇒ Boolean
81 82 83 |
# File 'lib/mongomodel/concerns/properties.rb', line 81 def internal? as =~ /^_/ || [:internal] end |
#validate? ⇒ Boolean
85 86 87 |
# File 'lib/mongomodel/concerns/properties.rb', line 85 def validate? [:validate] != false end |