Class: Vestroy::Model
- Inherits:
-
Object
- Object
- Vestroy::Model
- Defined in:
- lib/vestroy/model.rb
Instance Attribute Summary collapse
-
#collected_errors ⇒ Object
readonly
Returns the value of attribute collected_errors.
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(message) ⇒ Object
- #collect_errors ⇒ Object
- #destroy ⇒ Object
- #destroyable? ⇒ Boolean
-
#initialize(object) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(object) ⇒ Model
Returns a new instance of Model.
7 8 9 10 |
# File 'lib/vestroy/model.rb', line 7 def initialize(object) @object = object @collected_errors = [] end |
Instance Attribute Details
#collected_errors ⇒ Object (readonly)
Returns the value of attribute collected_errors.
5 6 7 |
# File 'lib/vestroy/model.rb', line 5 def collected_errors @collected_errors end |
Class Method Details
.destroys(name) ⇒ Object
12 13 14 15 16 |
# File 'lib/vestroy/model.rb', line 12 def self.destroys(name) define_method(name) do @object end end |
Instance Method Details
#add_error(message) ⇒ Object
36 37 38 |
# File 'lib/vestroy/model.rb', line 36 def add_error() collected_errors << end |
#collect_errors ⇒ Object
31 32 33 34 |
# File 'lib/vestroy/model.rb', line 31 def collect_errors # default error message add_error(I18n.t('vestroy.could_not_be_destroyed')) if collected_errors.empty? end |
#destroy ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/vestroy/model.rb', line 18 def destroy if destroyed_object = (destroyable? && @object.destroy) destroyed_object else collect_errors raise Vestroy::Error.new("#{collected_errors.to_sentence}.") end end |
#destroyable? ⇒ Boolean
27 28 29 |
# File 'lib/vestroy/model.rb', line 27 def destroyable? true end |