Module: Familia::Features::Housekeeping::ModelInstanceMethods
- Defined in:
- lib/familia/features/housekeeping.rb
Overview
Housekeeping::ModelInstanceMethods
Instance Method Summary collapse
-
#do_chore!(name) ⇒ Object
Run a single registered chore by name.
-
#do_chores! ⇒ Hash{Symbol => Object}
(also: #tidy!)
Run every registered chore against this instance.
Instance Method Details
#do_chore!(name) ⇒ Object
Run a single registered chore by name.
172 173 174 175 176 177 178 179 180 |
# File 'lib/familia/features/housekeeping.rb', line 172 def do_chore!(name) raise ArgumentError, 'chore name required' if name.nil? || name.to_s.empty? key = name.to_sym registered = self.class.chores raise ArgumentError, "unknown chore #{name.inspect}" unless registered.key?(key) registered[key].call(self) end |
#do_chores! ⇒ Hash{Symbol => Object} Also known as: tidy!
Run every registered chore against this instance.
185 186 187 188 189 |
# File 'lib/familia/features/housekeeping.rb', line 185 def do_chores! self.class.chores.each_with_object({}) do |(chore_name, block), results| results[chore_name] = block.call(self) end end |