Class: Sublease::Lodger
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Sublease::Lodger
- Defined in:
- app/models/sublease/lodger.rb
Class Method Summary collapse
-
.belongs_to_sublease(tenant, options = {}) ⇒ Object
Establishes an ActiveRecord Association.
-
.delete(id_or_array) ⇒ Object
Overrides standard ActiveRecord::Relation delete to call destroy instead ensuring all callbacks are fired.
Instance Method Summary collapse
-
#allow_sublease_change ⇒ Object
Allow the sublease to be changed if true.
-
#allow_sublease_change=(tf) ⇒ Object
Allows the sublease to be changed.
-
#allow_sublease_change? ⇒ Boolean
Checks if the sublease can be changed.
-
#delete ⇒ Object
Overrides standard object delete to call destroy instead ensuring all callbacks are fired.
Class Method Details
.belongs_to_sublease(tenant, options = {}) ⇒ Object
Establishes an ActiveRecord Association. Takes the same options as ActiveRecord::Associations::ClassMethods belong_to except it will ignore the dependent option in order to prevent destroying tenant on destruction of lodger. Validates presence of tenant id.
17 18 19 20 21 22 23 24 25 |
# File 'app/models/sublease/lodger.rb', line 17 def belongs_to_sublease(tenant, = {}) belongs_to tenant.to_sym, .delete(:dependent) before_validation -> {valid_sublease_change(tenant)}, on: :update validates "#{tenant}_id".to_sym, presence: true validate -> {valid_sublease_tenant(tenant)} end |
.delete(id_or_array) ⇒ Object
Overrides standard ActiveRecord::Relation delete to call destroy instead ensuring all callbacks are fired.
10 11 12 |
# File 'app/models/sublease/lodger.rb', line 10 def delete(id_or_array) destroy(id_or_array) end |
Instance Method Details
#allow_sublease_change ⇒ Object
Allow the sublease to be changed if true. Returns true or false.
29 30 31 |
# File 'app/models/sublease/lodger.rb', line 29 def allow_sublease_change @allow_sublease_change ||= false end |
#allow_sublease_change=(tf) ⇒ Object
Allows the sublease to be changed. Set using true or false.
34 35 36 |
# File 'app/models/sublease/lodger.rb', line 34 def allow_sublease_change=(tf) @allow_sublease_change = tf.class == TrueClass ? true : false end |
#allow_sublease_change? ⇒ Boolean
Checks if the sublease can be changed. Returns true or false.
39 40 41 |
# File 'app/models/sublease/lodger.rb', line 39 def allow_sublease_change? allow_sublease_change end |
#delete ⇒ Object
Overrides standard object delete to call destroy instead ensuring all callbacks are fired.
44 45 46 |
# File 'app/models/sublease/lodger.rb', line 44 def delete destroy end |