Module: Ambry::ActiveModel::ClassMethods

Defined in:
lib/ambry/active_model.rb

Instance Method Summary collapse

Instance Method Details

#create(*args) ⇒ Object

Create and save a model instance, returning false if any errors occur.



54
55
56
57
58
# File 'lib/ambry/active_model.rb', line 54

def create(*args)
  new(*args).save!
rescue AmbryError
  false
end

#create!(*args) ⇒ Object

Create and save a model instance, raising an exception if any errors occur.



48
49
50
# File 'lib/ambry/active_model.rb', line 48

def create!(*args)
  new(*args).save!
end

#model_nameObject



65
66
67
# File 'lib/ambry/active_model.rb', line 65

def model_name
  @model_name ||= ::ActiveModel::Name.new(self)
end

#validates_uniqueness_of(*attr_names) ⇒ Object

Validate the uniqueness of a field’s value in a model instance.



61
62
63
# File 'lib/ambry/active_model.rb', line 61

def validates_uniqueness_of(*attr_names)
  validates_with Validations::Uniqueness, _merge_attributes(attr_names)
end