Module: Hideable::ActiveRecord::InstanceMethods
- Defined in:
- lib/hideable/active_record/instance_methods.rb
Instance Method Summary collapse
- #hidden? ⇒ Boolean
- #hide! ⇒ Object
- #unhide! ⇒ Object
- #update_hideable_dependents! ⇒ Object
- #update_hideable_dependents? ⇒ Boolean
Instance Method Details
#hidden? ⇒ Boolean
5 6 7 |
# File 'lib/hideable/active_record/instance_methods.rb', line 5 def hidden? self.hidden_at.is_a?(DateTime) end |
#hide! ⇒ Object
9 10 11 12 13 |
# File 'lib/hideable/active_record/instance_methods.rb', line 9 def hide! return if self.hidden? self.hidden_at = DateTime.now self.save! end |
#unhide! ⇒ Object
15 16 17 18 19 |
# File 'lib/hideable/active_record/instance_methods.rb', line 15 def unhide! return unless self.hidden? self.hidden_at = nil self.save! end |
#update_hideable_dependents! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hideable/active_record/instance_methods.rb', line 25 def update_hideable_dependents! self.class.reflect_on_all_associations.each do |reflection| if update_reflected_record?(reflection) dependent_records = Array(self.send(reflection.name)).compact dependent_records.each do |record| action = self.hidden? ? :hide! : :unhide! record.send(action) if record.respond_to?(action) end end end end |
#update_hideable_dependents? ⇒ Boolean
21 22 23 |
# File 'lib/hideable/active_record/instance_methods.rb', line 21 def update_hideable_dependents? self.class.hide_dependents && self.hidden_at_changed? end |