Module: Familia::Features::Housekeeping::ModelClassMethods
- Defined in:
- lib/familia/features/housekeeping.rb
Overview
Housekeeping::ModelClassMethods
Instance Method Summary collapse
-
#chore(name) {|obj| ... } ⇒ Proc
Register a chore by name.
-
#chores ⇒ Hash{Symbol => Proc}
Registered chores in registration order.
Instance Method Details
#chore(name) {|obj| ... } ⇒ Proc
Register a chore by name. The block receives the instance.
59 60 61 62 63 64 |
# File 'lib/familia/features/housekeeping.rb', line 59 def chore(name, &block) raise ArgumentError, 'chore name required' if name.nil? || name.to_s.empty? raise ArgumentError, "chore #{name.inspect} requires a block" unless block chores[name.to_sym] = block end |
#chores ⇒ Hash{Symbol => Proc}
Registered chores in registration order. Subclasses inherit a copy of their parent's chores on first access, so registering a new chore on a subclass does not mutate the parent.
71 72 73 74 75 76 77 |
# File 'lib/familia/features/housekeeping.rb', line 71 def chores @chores ||= if superclass.respond_to?(:chores) superclass.chores.dup else {} end end |