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.
183 184 185 186 187 188 189 190 191 |
# File 'lib/familia/features/housekeeping.rb', line 183 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.
196 197 198 199 200 |
# File 'lib/familia/features/housekeeping.rb', line 196 def do_chores! self.class.chores.each_with_object({}) do |(chore_name, handler), results| results[chore_name] = handler.call(self) end end |