Module: Familia::Features::Housekeeping
- Defined in:
- lib/familia/features/housekeeping.rb
Overview
Housekeeping registers named cleanup chores on a Horreum class and runs them against a single instance. It is intended for short-lived, repeated tidying of fields whose values have drifted (e.g. running nightly for a few days, then removing the chore once data is clean).
The feature owns registration and per-instance execution only. Iteration, batching, scheduling, error aggregation, and persistence are the caller's responsibility.
Example:
class Organization < Familia::Horreum feature :housekeeping field :planid
chore :standardize_planid do |org|
canonical = case org.planid
when 'pro', 'Pro', 'professional_v1' then 'professional'
when 'free', 'Free', 'basic' then 'free'
end
if canonical && canonical != org.planid
org.planid = canonical
org.save
true
end
end
end
org = Organization.from_identifier('acme-corp') org.tidy! # => { standardize_planid: true }
org.tidy!(:standardize_planid) # => { standardize_planid: true }
See docs/guides/feature-housekeeping.md for the full guide.
Defined Under Namespace
Modules: ModelClassMethods
Instance Method Summary collapse
-
#tidy!(name = nil) ⇒ Hash{Symbol => Object}
Run all registered chores, or one chore by name.
Instance Method Details
#tidy!(name = nil) ⇒ Hash{Symbol => Object}
Run all registered chores, or one chore by name.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/familia/features/housekeeping.rb', line 85 def tidy!(name = nil) registered = self.class.chores if name key = name.to_sym raise ArgumentError, "unknown chore #{name.inspect}" unless registered.key?(key) { key => registered[key].call(self) } else registered.each_with_object({}) do |(chore_name, block), results| results[chore_name] = block.call(self) end end end |