Module: Guacamole::Model
- Extended by:
- ActiveModel::Naming, ActiveSupport::Concern
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations, Virtus
- Defined in:
- lib/guacamole/model.rb
Overview
This is not a model according to the active record pattern. It does not know anything about the database.
A domain model of your application
A Guacamole::Model represents a single entry in your collection or an embedded entry of another entry. You use this as a Mixin in your model classes.
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
Timestamp of the creation of this document.
-
#key ⇒ String
readonly
Key of the document in the collection.
-
#rev ⇒ String
readonly
The revision of the document.
-
#updated_at ⇒ Time
readonly
Timestamp of the last update of this document.
Class Method Summary collapse
-
.attribute(attribute_name, type) ⇒ Object
Define an attribute for this model (Provided by Virtus).
-
.callbacks(name_of_callbacks_class) ⇒ Object
Registers a single callback class to be used for this model.
-
.validate ⇒ Object
Adds a validation method or block to the class.
-
.validates ⇒ Object
This method is a shortcut to all default validators and any custom validator classes ending in 'Validator'.
-
.validates_with ⇒ Object
Passes the record off to the class or classes specified.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Check if the attributes are from the same model class and have equal attributes.
-
#callbacks ⇒ Callback
private
Returns the registered callback class instantiated with
self
. -
#errors ⇒ Object
Returns the Errors object that holds all information about attribute error messages.
-
#invalid? ⇒ Object
Performs the opposite of
valid?
. -
#persisted? ⇒ Boolean
Checks if the object is persisted.
-
#valid? ⇒ Object
Runs all the specified validations and returns true if no errors were added otherwise false.
Instance Attribute Details
#created_at ⇒ Time (readonly)
Only set when persisted
Timestamp of the creation of this document
This will automatically be set when the document was first saved to the database.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#key ⇒ String (readonly)
Only set when persisted
Key of the document in the collection
The key identifies a document distinctly within one collection.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#rev ⇒ String (readonly)
Only set when persisted
The revision of the document
ArangoDB keeps changes the revision of a document automatically, when it has changed. With this functionality you can quickly find out if you have the most recent version of the document.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#updated_at ⇒ Time (readonly)
Only set when persisted
Timestamp of the last update of this document
This will automatically be changed whenever the document is saved.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
Class Method Details
.attribute(attribute_name, type) ⇒ Object
Setting the value of an attribute leads to automatic coercion
Define an attribute for this model (Provided by Virtus)
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
.callbacks(name_of_callbacks_class) ⇒ Object
Registers a single callback class to be used for this model
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
.validate ⇒ Object
Adds a validation method or block to the class
For further details see the documentation of ActiveModel or the RailsGuide on Validations
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
.validates ⇒ Object
This method is a shortcut to all default validators and any custom validator classes ending in 'Validator'
For further details see the documentation of ActiveModel or the RailsGuide on Validations
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
.validates_with ⇒ Object
Passes the record off to the class or classes specified
This and allows to add errors based on more complex conditions
For further details see the documentation of ActiveModel or the RailsGuide on Validations
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
Instance Method Details
#==(other) ⇒ Object
Check if the attributes are from the same model class and have equal attributes
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#callbacks ⇒ Callback
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the registered callback class instantiated with self
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#errors ⇒ Object
Returns the Errors object that holds all information about attribute error messages
For further details see the documentation of ActiveModel or the RailsGuide on Validations
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#invalid? ⇒ Object
Performs the opposite of valid?
. Returns true if errors were added, false otherwise
For further details see the documentation of ActiveModel or the RailsGuide on Validations
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#persisted? ⇒ Boolean
Checks if the object is persisted
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |
#valid? ⇒ Object
Runs all the specified validations and returns true if no errors were added otherwise false
For further details see the documentation of ActiveModel or the RailsGuide on Validations
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/guacamole/model.rb', line 186 module Model extend ActiveSupport::Concern # @!parse include ActiveModel::Validations # @!parse extend ActiveModel::Naming # @!parse include ActiveModel::Conversion # I know that this is technically not true, but the reality is a parse error: # @!parse include Virtus module ClassMethods def callbacks(name_of_callbacks_class) callback_class = name_of_callbacks_class.to_s.camelcase.constantize Callbacks.register_callback self, callback_class end end included do include ActiveModel::Validations extend ActiveModel::Naming include ActiveModel::Conversion include Virtus.model attribute :key, String attribute :rev, String attribute :created_at, Time attribute :updated_at, Time def persisted? key.present? end # For ActiveModel::Conversion compliance only, please use key def id key end def _id persisted? ? [self.class.name.underscore.pluralize, key].join('/') : nil end def valid_with_callbacks?(context = nil) callbacks.run_callbacks :validate do valid_without_callbacks?(context) end end alias_method :valid_without_callbacks?, :valid? alias_method :valid?, :valid_with_callbacks? def callbacks Guacamole::Callbacks.callbacks_for(self) end def ==(other) other.instance_of?(self.class) && attributes.all? do |attribute, value| other_value = other.send(attribute) case value when DateTime, Time value.to_s == other_value.to_s # :( else value == other_value end end end alias_method :eql?, :== end end |