Module: Familia::Features::Housekeeping::ModelClassMethods

Defined in:
lib/familia/features/housekeeping.rb

Overview

Housekeeping::ModelClassMethods

Instance Method Summary collapse

Instance Method Details

#chore(name) {|obj| ... } ⇒ Proc

Register a chore by name. The block receives the instance.

Parameters:

  • name (Symbol, String)

    chore identifier

Yields:

  • (obj)

    block invoked with the instance during tidy!

Returns:

  • (Proc)

    the registered block

Raises:

  • (ArgumentError)

    if name is blank or no block is given



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

#choresHash{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.

Returns:

  • (Hash{Symbol => Proc})


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