Module: ModestModel::Tenacity::InstanceMethods

Defined in:
lib/modest_model/tenacity.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject

Runs the destroy block and sets the resource as destroyed



122
123
124
125
126
# File 'lib/modest_model/tenacity.rb', line 122

def destroy
  call_destroy!
  @destroyed = true
  return self
end

#destroyed?Boolean

:nodoc:

Returns:

  • (Boolean)


103
104
105
# File 'lib/modest_model/tenacity.rb', line 103

def destroyed? #:nodoc:
  @destroyed
end

#foundObject

:nodoc:



89
90
91
92
# File 'lib/modest_model/tenacity.rb', line 89

def found #:nodoc:
  @new_resource = false
  return self
end

#initialize(attributes = {}, options = {}) ⇒ Object

:nodoc:



83
84
85
86
87
# File 'lib/modest_model/tenacity.rb', line 83

def initialize attributes = {}, options={} #:nodoc:
  super attributes, options
  @new_resource = true
  @destroyed  = false
end

#new_resource?Boolean Also known as: new_record?

:nodoc:

Returns:

  • (Boolean)


98
99
100
# File 'lib/modest_model/tenacity.rb', line 98

def new_resource? #:nodoc:
  @new_resource
end

#persisted?Boolean

:nodoc:

Returns:

  • (Boolean)


107
108
109
# File 'lib/modest_model/tenacity.rb', line 107

def persisted? #:nodoc:
  false
end

#saveObject

Runs the save block and returns true if the operation was successful, false if not



112
113
114
# File 'lib/modest_model/tenacity.rb', line 112

def save(*)
  create_or_update
end

#save!Object

Runs the save block and returns true if the operation was successful or raises an InvalidResource error if not



117
118
119
# File 'lib/modest_model/tenacity.rb', line 117

def save!(*)
  create_or_update || raise(ModestModel::InvalidResource)
end

#to_paramObject

:nodoc:



94
95
96
# File 'lib/modest_model/tenacity.rb', line 94

def to_param #:nodoc:
  send(self.class.primary_key)
end

#update_attribute(name, value) ⇒ Object

Updates a single attribute and calls save. This is especially useful for boolean flags on existing records. Also note that

  • Validation is skipped.

  • Callbacks are invoked.



134
135
136
137
# File 'lib/modest_model/tenacity.rb', line 134

def update_attribute(name, value)
  send("#{name.to_s}=", value)
  save(:validate => false)
end

#update_attributes(attributes, options = {}) ⇒ Object

Updates the attributes of the model from the passed-in hash and calls save the will fail and false will be returned.



141
142
143
144
# File 'lib/modest_model/tenacity.rb', line 141

def update_attributes(attributes, options = {})
  self.assign_attributes(attributes, options)
  save
end

#update_attributes!(attributes, options = {}) ⇒ Object

Updates its receiver just like update_attributes but calls save! instead of save, so an exception is raised if the resource is invalid.



148
149
150
151
# File 'lib/modest_model/tenacity.rb', line 148

def update_attributes!(attributes, options = {})
  self.assign_attributes(attributes, options)
  save!
end