Module: Guacamole::Model

Extended by:
ActiveModel::Naming, ActiveSupport::Concern
Includes:
ActiveModel::Conversion, ActiveModel::Validations, Virtus
Defined in:
lib/guacamole/model.rb

Overview

Note:

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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#created_atTime (readonly)

Note:

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.

Returns:

  • (Time)

    Timestamp of the creation of the model in 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

#keyString (readonly)

Note:

Only set when persisted

Key of the document in the collection

The key identifies a document distinctly within one collection.

Returns:

  • (String)

    The key 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

#revString (readonly)

Note:

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.

Returns:

  • (String)

    The revision 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_atTime (readonly)

Note:

Only set when persisted

Timestamp of the last update of this document

This will automatically be changed whenever the document is saved.

Returns:

  • (Time)

    Timestamp of the last update in 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

Class Method Details

.attribute(attribute_name, type) ⇒ Object

Note:

Setting the value of an attribute leads to automatic coercion

Define an attribute for this model (Provided by Virtus)

Examples:

Define an attribute of type String

class BlogPost
  include Guacamole::Model

  attribute :title, String
end

Define an attribute containing an array of Strings

class Repository
  include Guacamole::Model

  attribute :contributor_names, Array[String]
end

Parameters:

  • attribute_name (Symbol)

    The name of the attribute to define

  • type (Class)

    The type of the attribute

See Also:



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

Examples:

class BlogPost
  include Guacamole::Model

  callbacks :blog_post_callbacks
end

Parameters:

  • name_of_callbacks_class (Symbol)

    The name of the the callback class to be used



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

.validateObject

Adds a validation method or block to the class

For further details see the documentation of ActiveModel or the RailsGuide on Validations

Examples:

Validate that the person is awesome

class Person
  include Guacamole::Model
  validate :is_awesome

  def is_awesome
    # Check if the person is awesome
  end
end

See Also:



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

.validatesObject

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

Examples:

Validate the presence of the name

class Person
  include Guacamole::Model

  attribute :name, String
  validates :name, presence: true
end

See Also:



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_withObject

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

Examples:

Validate that the person is awesome

class Person
  include Guacamole::Model
  validates_with PersonValidator
end

class PersonValidator < ActiveModel::Validator
  def validate(record)
    # check if the person is valid
  end
end

See Also:



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

Parameters:

  • other (Model)

    the model to compare with



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

#callbacksCallback

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

Returns:

  • (Callback)

    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

#errorsObject

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

Returns:

  • (Boolean)


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