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.



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

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.



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

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

#model_nameObject



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

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.



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

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